background preloader

C++

Facebook Twitter

C++ Reference Wiki. Polymorphism. Before getting any deeper into this chapter, you should have a proper understanding of pointers and class inheritance. If you are not really sure of the meaning of any of the following expressions, you should review the indicated sections: Pointers to base class One of the key features of class inheritance is that a pointer to a derived class is type-compatible with a pointer to its base class. Polymorphism is the art of taking advantage of this simple but powerful and versatile feature. The example about the rectangle and triangle classes can be rewritten using pointers taking this feature into account: Function main declares two pointers to Polygon (named ppoly1 and ppoly2).

Dereferencing ppoly1 and ppoly2 (with *ppoly1 and *ppoly2) is valid and allows us to access the members of their pointed objects. Virtual members A virtual member is a member function that can be redefined in a derived class, while preserving its calling properties through references. Abstract base classes.

ADS4

Teach Yourself C++ in 21 Days. Bruce Eckel's Free Electronic Books. C++ Reference [C++ Reference] The Boost C++ Libraries.