This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13937] virtual method hides overloaded method in base class
- From: "gdr at integrable-solutions dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Jan 2004 19:46:48 -0000
- Subject: [Bug c++/13937] virtual method hides overloaded method in base class
- References: <20040130193347.13937.msieweke@broadcom.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From gdr at integrable-solutions dot net 2004-01-30 19:46 -------
Subject: Re: New: virtual method hides overloaded method in base class
"msieweke at broadcom dot com" <gcc-bugzilla@gcc.gnu.org> writes:
| // This function tries to get hold of the Thingy object, which should resolve
| // to A::Value(void); however, the compiler seems unable to make this
| // connection.
This is not a bug in the compiler. That is how the compiler is
supposed to behave according to C++ standard. It is almost always
troublesome to overload a virtual function.
See C++ standard 10.2/2
The following steps define the result of name lookup in a class
scope, C. First, every declaration for the name in the class and in
each of its base class subobjects is considered. A member name f in
one subobject B hides a member name f in a subobject A if A is a
base class subobject of B. Any declarations that are so hidden are
eliminated from consideration. [...]
[...]
| If we change the code to:
|
| pThingy = ((A *) pMyB)->Value();
|
| it will compile without complaint.
Yes, that works because the static type of the left-most postfix
expression is A* and name lookup starts within A::.
-- Gaby
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13937