Start of topic | Skip to actions
Abstract ClassesAbstract classes are defined just as ordinary classes. However, some of their methods are designated to be necessarily defined by subclasses. We just mention their signature including their return type, name and parameters but not a definition. One could say, we omit the method body or, in other words, specify "nothing". This is expressed by appending "= 0" after the method signatures:
class DrawableObject {
...
public:
...
virtual void print() = 0;
};
This class definition would force every derived class from which objects should be created to define a method print(). These method declarations are also called pure methods.
Pure methods must also be declared virtual, because we only want to use objects from derived classes. Classes which define pure methods are called abstract classes.
%HELPEDITING% Comments | |||||