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]

Re: bug report



This is not a bug in gcc; this is a bug in your code.        
        
13/1
# When two or more different declarations are specified for a single
# name in the same scope, that name is said to overloaded.
        
13.2/1
# Two function declarations of the same name refer to the same
# function if they are in the same scope and have equivalent parameter
# declarations (13.1). A function member of a derived class is not in
# the same scope as a function member of the same name in a base
# class.

13.2 goes on to include a code example very similar to yours.

B::boo(int) and A::boo() are not in the same scope, so
  B::boo(int) does not overload A::boo().

Instead, A::boo() is hidden by B::boo(int). So if you must call
  A::boo(), you need to qualify it: b->A::boo() for example.

I believe the reasoning behind this decision was to prevent code that
  uses a derived class (class B in your example) from undergoing
  mysterious changes in behavior whenever a new function is added to
  the base class (A in your examle).

If you disagree with this analysis, please discuss it on comp.std.c++
  or comp.lang.c++.moderated .

[snip]          
> orlovm-silver:~/progs/c> g++ -o a a.cc
> a.cc: In function `int main()':
> a.cc:17: no matching function for call to `B::boo ()'
> a.cc:10: candidates are: int B::boo(int)
> a.cc:18: no matching function for call to `B::boo ()'
> a.cc:10: candidates are: int B::boo(int)
> 
> Source
> ------
> 
> #include <iostream.h>
> 
> class A {
> public:
>   int boo() { return 1; }
> };
> 
> class B : public A {
> public:
>   int boo(int a) { return a; }
> };
> 
> 
> int main() {
>   B *b = new B();
>   B bb;
>   cout << "Blah: " << b->boo() << endl;
>   cout << "Blah: " << bb.boo() << endl;
>   delete b;
>   return 0;
> }
> 
[snip]

Thank you for your time.




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