Topic: Derivation and overloading
Author: Oren Cheyette <Oren.Cheyette@barra.com>
Date: 1997/01/07 Raw View
I am puzzled by the following behavior that appears to be part of an
"unofficial" standard: I have observed this with several compilers, and
some of the engineers around here have confirmed that this is "correct"
behavior. On the other hand, I find nothing about it in Stroustrup...
The following code fails to compile. The virtual function redefinition
in the derived class D "hides" the non-virtual base class function with
different signature. Making the base class non-virtual function virtual
doesn't help. The compiler still gets confused. Can someone explain
1) is this correct behavior, and 2) if so, why?
class A {
// ...
};
class B {
public:
B(A & x) : a(x);
virtual void foo(int, const A &);
void foo(int i) { return foo(i, a); } // get some default //
behavior
protected:
A a;
};
class D : public B {
public:
void foo(int, const A &);// redefined function, but we'd
// like the same default behavior
};
main()
{
A a;
D d(a);
d.foo(1);
}
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Matt Seitz <mseitz@meridian-data.com>
Date: 1997/01/07 Raw View
Oren Cheyette wrote:
> The following code fails to compile. The virtual function redefinition
> in the derived class D "hides" the non-virtual base class function with
> different signature. Making the base class non-virtual function virtual
> doesn't help. The compiler still gets confused. Can someone explain
> 1) is this correct behavior,