Found:
Ambiguity while overloading the cast operator
and
not helpful
Situation:
Inside the container class's body I have:
operator T& () const {
return *data;
}
operator const T& () const {
return *data;
}
The intent being that:
container<object> test = new object;
object& whatever = test; //<--uses (T&) cast
const object& other = test; //<--uses (const T&) cast
However the second one causes an error because it is ambiguous.
I completely see why the compiler is complaining, it is okay to assign a object&
and a const object&
to a const object&
however I'd like it to not complain and choose the second (return const object&
)
Oh wait, just got my answer.