> > I have the following code :
> > struct Toto { void Add(int x){} };
> > struct Titi : public Toto { void Add(int x, int y){} };
> > int main ()
> > {
> > Titi titi;
> > titi.Add(1);
> > }
> > And both MSVC 7 and gcc give me=20
> > error : 'Titi::Add' : function does not take 1 parameters
> > sure i could write titi.Toto::Add(1); and this will work but
> > i want to avoid such a pain.
> > is it a C++ specification problem or a compiler problem ?
Guessing wildly, I'd say the compiler uses rules that cover the
most cases possible. So, the behavior in the case of:
class A { public: void F( int i ){} };
class B : public A { public: void F( int i, int j ){}; }
main(){ B x; x.F(1); }
is really the same as in:
class A { public: void F( int i ){} };
class B : public A { public: void F( int i ){}; }
class C : public B { public: void F( int i ){}; }
class D : public C { public: void F( int i ){}; }
class E : public D { public: void F( int i, int j ){}; }
main(){ E x; x.F(1); }
and is the same for multiple-inheritance, too:
class A { public: void F( int i ){} };
class B { public: void F( int i ){} };
class C { public: void F( int i ){} };
class D { public: void F( int i ){} };
class E : public A, public B, public C, public D
{ public: void F( int i, int j ){}; }
main(){ E x; x.F(1); }
Okay, I might be totally wrong. It's been a while since I
looked in to these things. But it is my instinct to think
that whatever rule is applied in the simple case mentioned
is not designed to drive people insane, but is instead is a
case in which a good general rule seems not so good.
--- Colin
P.S.: In Soviet Russia... ...code compiles YOU!!!
|