I have a code similar to this:
template <typename T>
struct B
{
B &operator =(const T &) { return *this; }
};
struct D : B<int> {};
int main()
{
D d;
d = 0;
return 0;
}
Which fails:
error: no viable overloaded '='
d = 0;
~ ^ ~
note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const D' for 1st argument
struct D : B<int> {};
^
note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'int' to 'D' for 1st argument
struct D : B<int> {};
^
The error is easy to spot and understand: D lacks of assignment operator with int, even if its base class have it. From c++11 onwards we can solve this issue "lifting" to the derived object the assignment operator from the base object:
struct D : B<int> { using B::operator =; /* Easy fix! */ };
But I'm working on a c++98 project, so this fix isn't available. How was this solved prior to C++11?