class Base
{
public:
int m_Data;
const Base& operator=(int pData)
{ m_Data = pData; return *this;}
};
class ChildOne : public Base
{
public:
void someFunc() {};
};
class ChildTwo : public Base
{
public:
void someFunc() {};
using Base::operator=;
};
int main()
{
ChildOne l_1;
ChildTwo l_2;
l_1 = 1;
l_2 = 2;
return 0;
}
Quote
"ComeauTest.c", line 27: error: no operator "=" matches these operands
operand types are: ChildOne = int
l_1 = 1;
^
operand types are: ChildOne = int
l_1 = 1;
^
Quote
-1- An assignment operator shall be implemented by a non-static member function with exactly one parameter. Because a copy assignment operator operator= is implicitly declared for a class if not declared by the user (class.copy), a base class assignment operator is always hidden by the copy assignment operator of the derived class.
If my Base::operator=(int) is automatically hidden, is there some reason why 'unhiding it' as done in ChildTwo is dangerous? (possibly automatic type conversions :unsure: )












