I was trying to create two classes, the first with a non-const implementation of the functions, the second with a const implementation. Here is a small example:
class Base {
protected:
int some;
};
class A : public virtual Base {
const int& get() const {
return some;
}
};
class B : public virtual Base {
int& get() {
return some;
}
};
class C : public A, B {};
C test;
test.get(); // ambiguous
The call to the get
function is ambiguous. No matter that the const version needs to match more requirements. (Calling get
on const C
is ambiguous as well, but there is one possible function to call.)
Is there a reason for such behaviour in the standard? Thanks!