April 2017
Beginner to intermediate
394 pages
9h 16m
English
Astute readers will also have noticed that the return types of each Clone method in the Mach5 Engine are actually different. The base M5Component class returns an M5Component*, however the derived classes return pointers to their own class types. This is a feature of C++ (as well as some other languages) known as covariant return types. Let's look at this feature using the Shape class from above:
class Shape { public: virtual ~Shape(void) {}//empty base class constructor virtual void Draw(void) const = 0; virtual Shape* Clone(void) const = 0; }; class Circle : public Shape { public: virtual void Draw(void) const; virtual Shape* Clone(void) const; }; int main(void) { Circle* pCircle = new Circle(); //The line ...Read now
Unlock full access