| re: C++ theory
"Kalle Rutanen" <none@here.com> wrote in message
news:d118mn$jq5$1@news.cc.tut.fi[color=blue]
> Why does this short program compile (compiled fine on msvcnet2003) ?
>
> class A
> {
> public:
> void set()
> {
> }
> };
>
> class B: public A
> {
> public:
> using A::set;
>
> void set()
> {
> }
> };
>
> int main()
> {
> B b;
>
> // Shouldn't this call be ambiguous ?
> b.set();
>
> return 0;
> }[/color]
In some contexts, you would be right, but not in this context. Section
7.3.3, p12 of the C++ standard says:
<quote>
When a using-declaration brings names from a base class into a derived class
scope, member functions in the derived class override and/or hide member
functions with the same name and parameter types in a base class (rather
than conflicting). [Example:
struct B {
virtual void f(int);
virtual void f(char);
void g(int);
void h(int);
};
struct D : B {
using B::f;
void f(int); // OK: D::f(int) overrides B::f(int);
using B::g;
void g(char); // OK
using B::h;
void h(int); // OK: D::h(int) hides B::h(int)
};
void k(D* p)
{
p->f(1); //calls D::f(int)
p->f('a'); //calls B::f(char)
p->g(1); //calls B::g(int)
p->g('a'); //calls D::g(char)
}
-end example] [Note: two using-declarations may introduce functions with the
same name and the same parameter types. If, for a call to an unqualified
function name, function overload resolution selects the functions introduced
by such using-declarations, the function call is ill-formed. ]
</quote>
--
John Carson |