This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Can a base class figure out if any virtual functions were overwriten?
- To: adriang at adriang dot ce dot mediaone dot net, egcs at egcs dot cygnus dot com
- Subject: Re: Can a base class figure out if any virtual functions were overwriten?
- From: mrs at wrs dot com (Mike Stump)
- Date: Tue, 22 Dec 1998 11:25:52 -0800
> Date: Mon, 21 Dec 1998 23:09:07 -0600 (EST)
> From: <adriang@adriang.ce.mediaone.net>
> To: egcs@egcs.cygnus.com
> In the following code, I would expect to discover that M1 was
> changed. But it doesn't happen.
You might want to pick up a book on C++ and read about the language
some more. It should help in understanding the semantic of code you
write.
> 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?
> if (M1 != Base::M1)
> std::cout << "M1 different\n";
> if (M2 != Base::M2)
> std::cout << "M2 different\n";
First, this isn't valid ANSI C++, as the compiler will tell you when
you compile with -fpedantic-errors. The extension, is to assume that
you spelled the request for a pointer-to-member-function correctly,
like so:
> if (&Base::M1 != &Base::M1)
> std::cout << "M1 different\n";
> if (&Base::M2 != &Base::M2)
> std::cout << "M2 different\n";
and then compile it. In this light, you can see that this is not
permitted to say anything is different.
Now onto the meta comment, it sounds as if you haven't bought into the
idea of C++ yet. The idea is to hide stuff, modularize stuff, and
prevent the type of code that you seem to want to write. :-)