This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Can a base class figure out if any virtual functions were overwriten?


> 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.  :-)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]