I was going through the following code in Bjarne Stroustrups book, when i encountered the following code :
1 2 3 4 5 6
|
Shape* fct() {
Text tt{Point{200,200},"Annemarie"}
Shape* p = new Text{Point{100,100}, "Nicholas"};
return p;
}
|
Can somebody elaborate on line 4. I mean when what kind of code would it be ,where it is useful to use
instead of
and VICE -VERSA
Thanks!
Last edited on
Was there word polymorphism in that chapter?
@Aceix and how would and when would it come to use, to allocate a derived class's
constructor to that of a base class..
You don't. Not "constructor in constructor".
You store the address of an object in a pointer.
Derived inverits its base and therefore derived IS-A base and can be used where base is used.
Websearch polymorphism.