Meaning of Shape *p=new Circle();

Shape and Circle are classes.Shape is the base class and Circle is derived from Shape class.Can someone tell me the meaning of the following statement:
Shape *p=new Circle();
Last edited on
Store the address of a Circle object in a pointer p. Circle inherits Shape and therefore Circle is a Shape and can be referred to as one. See polymorphism.
Also see "Object Slicing" for why using polymorphism this way can backfire on you if you don't design things right.
"Object Slicing" refer to the case where you assign an object of a derived class, to an object of the base class.
The keyword here is object. Not sure how you relate that to the OP's example.
Topic archived. No new replies allowed.