When using interfaces in c++; You have your abstract (parent) class. Then you have the child class which inherits from the parent class and implements the pure virtual functions.
When another class uses the (child) interface, what is the point in the abstract class at this point? If you try to use the parent type in a function, i.e returning the type Parent, you get compiler errors (presumably because the compiler doesn’t know how much memory to allocate).
Can anyone tell me how to do the above?
i.e
Parent = Shape.
Child = Rectangle.
Thrid class which contains method which returns the type Shape?
Thanks in advance for any help/information.
A big advantage is that all children share the same interface. If you have a second child inheriting from the parent (Child = Circle), then regardless of the specific subclass, both of them can use the same functions.
Imagine then that you have a vector with pointers to shapes (vector < Shape* >), then it doesn’t matter which shapes you have in the vector, if your base class Shape has a virtual method Draw(), you can use that method from each element of the vector without explicit knowledge how that Draw method is implemented.