Rogue Wave banner
Previous fileContentsIndexNext file
Click on the banner to return to the user guide home page.

19.1 Redefinition of Virtual Functions

If you subclass off an existing class and override a virtual function, make sure that the overriding function has exactly the same signature as the overridden function. This includes any const modifiers!

This problem arises particularly when creating new RWCollectable classes. For example:

class MyObject : public RWCollectable {
public:
  RWBoolean isEqual();                            // No "const" !
};

The compiler will treat this definition of isEqual() as completely independent of the isEqual() in the base class RWCollectable, because it is missing a const modifier. Hence, if called through a pointer:

MyObject obj;
  RWCollectable* c = &obj;
  c->isEqual();   // RWCollectable::isEqual() will get called!

Previous fileContentsIndexNext file

©Copyright 1997, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.