Topic: Ambiguity
Author: clamage@Eng.sun.com (Steve Clamage)
Date: 1996/04/23 Raw View
In article 3@CompuServe.COM, Martin Aupperle <100754.2730@CompuServe.COM> writes:
>I use const overloading like in
>
>struct A {
> int &f();
> int f() const;
> };
>
>
>When I define
>
>struct B : protected A {
> void g() { f()=3; } // not ambiguous
> };
>
>struct C : public B {
> void h() { f()=3; } // ambiguous
> };
You have found a compiler bug.
Overload resolution does not depend on accessibility. Overloading is
resolved before access checking is performed, so either both calls
must be ambiguous, or neither call is ambiguous.
The choice of which A::f to call depends on the constness of "this".
Function B::g is not a const member function, so it cannot call the const
version of A::f. Function C::h is likewise not const, so it also cannot
call the const version of A::f. I don't see any ambiguity.
---
Steve Clamage, stephen.clamage@eng.sun.com
[ 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: Martin Aupperle <100754.2730@CompuServe.COM>
Date: 1996/04/22 Raw View
I use const overloading like in
struct A {
int &f();
int f() const;
};
When I define
struct B : protected A {
void g() { f()=3; } // not ambiguous
};
struct C : public B {
void h() { f()=3; } // ambiguous
};
the call of A::f in C::h is ambiguous. The same call of f is not ambiguous in
B::g and it is also not in C if B were derived public instead of protected.
Is this behaviour correct, and if yes, what is the rationale?
Thanks, Martin.
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]