This is the mail archive of the gcc-bugs@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]
Other format: [Raw text]

[Bug c++/13937] virtual method hides overloaded method in base class


------- 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


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