I'm getting this error message:
Operator<< in base class not visible in derived class
My Code:
class Dummy {};
class SomethingElse {};
class XBase
{
public:
void noop() {};
void operator <<(Dummy d) {};
};
class A : public XBase
{
public:
void operator << (SomethingElse s) {} // When commenting out statement: No compile error!
};
int main()
{
Dummy dummy;
SomethingElse somethingelse;
XBase X;
A a;
X << dummy;
a << dummy; // why is Xbase::operator<< invisible, it's a different type
a << somethingelse;
}
Compiler error messages:
error C2679 : binary '<<' : no operator found which takes a right - hand operand of type 'Dummy' (or there is no acceptable conversion)
message : could be 'void A::operator <<(SomethingElse)'
message : while trying to match the argument list '(A, Dummy)'void operator <<(Dummy d) {}; in the base class "Xbase" becomes invisible by declaring any void operator <<(SomethingElse d) {}; in a derived class.
Why is this?
Tested with Visual Studio 19 C++ Compiler and GCC 7 under Linux (cross compiled with VS Studio 19)