This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Can a base class figure out if any virtual functions were overwriten?
- To: egcs at egcs dot cygnus dot com
- Subject: Can a base class figure out if any virtual functions were overwriten?
- From: <adriang at adriang dot ce dot mediaone dot net>
- Date: Mon, 21 Dec 1998 23:09:07 -0600 (EST)
In the following code, I would expect to discover that M1 was changed. But
it
doesn't happen.
Then I ask, is there any portable way to discover in the base class
whether or
not each of the virtual functions were overwritten in derived classes?
#include <iostream>
class Interface
{//this is the test case
public:
virtual void M1(void) = 0;
virtual void M2(void) = 0;
};
class Base : public Interface
{
public:
// standard implementation for both virtuals
void M1(void);
void M2(void);
void Check(void);
};
void Base::M1(void)
{
}
void Base::M2(void)
{
}
class Derived : public Base
{
// overwrite one of the virtuals
void M1(void);
};
void Derived::M1(void)
{
}
void Base::Check(void)
{
// check if the virtuals remained unchanged or were overwritten
if (M1 != Base::M1)
std::cout << "M1 different\n";
if (M2 != Base::M2)
std::cout << "M2 different\n";
}
void main(void)
{
Derived d;
// check on an object of the derived class
d.Check();
}