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: c++/3400: doesn't compile simple hierarchy with overlaoding


> 
> class A {public: void a() {};};class B: public A {public: void a(int n) {};};int main(void){ B b; b.a(); return 0;}
> 
> I get the error message:
> 
> test.cc: In function `int main()':
> test.cc:15: no matching function for call to `B::a ()'
> test.cc:8: candidates are: void B::a(int)
> 
> I believe the code is correct (so do all my colleagues). 

Nope. See the quote from the c++ standard below. In GCC 3.0,
you can fix the code by putting 
  using A::a();
into the class B.

  13.2  Declaration matching                                  [over.dcl]

1 Two function declarations of the same name refer to the same  function
  if  they  are in the same scope and have equivalent parameter declara-
  tions (_over.load_).  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.
  [Example:

          class B {
          public:
              int f(int);
          };

          class D : public B {
          public:
              int f(char*);
          };
  Here D::f(char*) hides B::f(int) rather than overloading it.
          void h(D* pd)
          {
              pd->f(1);       // error:
                              // D::f(char*) hides B::f(int)
              pd->B::f(1);    // ok
              pd->f("Ben");   // ok, calls D::f
          }
   --end example]





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