Thursday, March 19, 2009

Overriding and Virtual Function Matching

A virtual function could only be overridden by a function in a derived class with the same name and exactly the same argument and return type.

This avoided any form of run-time type checking of arguments and any need to keep more extensive type information around at run time.

class Base
{

public:
    virtual void f();   
    virtual void g(int);
};

class Derived : public Base
{
public:
    void f(int); //overrides Base::f()
    void g(char); //doesn't override Base::g()
};

No comments:

Post a Comment