In my main function, i expected to do something like that :
void main()
{
CClassFLOAT f;
f=1.0f;
}
But Visual Studio 2005 fails to compile it with the following error :
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'float' (or there is no acceptable conversion)
1 ) You are missing semicolons after the class bodies
2 ) You are using void main instead of int main
3 ) You didn't define the = operator for CClassFLOAT, if CClassFLOAT won't have any difference to TBase<float>, you can declare it as typedef: typedef TBase<float> CClassFLOAT;
Yes, this is because operator overloading and inheritance don't mesh seamlessly.
The method you are trying to call is CClassFLOAT& CClassFLOAT::operator=( float ), but
the method you've defined is (effectively) TBase& operator=( float ).
You are asking the compiler to perform an implicit downcast of a TBase& to a CClassFLOAT&.
Unfortunately you can't do that. You will need to move operator= to the derived type.