You are here: TWiki > CPP Web > TableOfContents > AbstractClassesAgain r1 - 22 Apr 2002 - 03:21 - TWikiGuest


Start of topic | Skip to actions

Abstract Classes

Abstract 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

Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r1 | More topic actions
This page is part of the GNA C++ Web.
Copyright © 2002 Globewide Network Academy. All material on this web is subject to the GNU rel="nofollow" Free Documentation License . We encourage you to copy the material on this site.
Ideas, requests, problems regarding TWiki? Send feedback.