Vladimir Grigoriev
2009-12-22 15:58:49 UTC
Let consider the code
struct A
{
};
struct B: public A
{
B() {}
B( const A &rhs ){}
B & operator ++()
{
return ( *this );
}
};
const B operator ++( B &lhs, int )
{
++lhs;
return ( B() );
}
int _tmain(int argc, _TCHAR* argv[])
{
A a;
a++;
}
Why does the compiler issue the error
error C2678: binary '++' : no operator found which takes a left-hand operand
of type 'A' (or there is no acceptable conversion)
could be 'const B operator ++(B &,int)'
while trying to match the argument list '(A, int)'
Vladimir Grigoriev
struct A
{
};
struct B: public A
{
B() {}
B( const A &rhs ){}
B & operator ++()
{
return ( *this );
}
};
const B operator ++( B &lhs, int )
{
++lhs;
return ( B() );
}
int _tmain(int argc, _TCHAR* argv[])
{
A a;
a++;
}
Why does the compiler issue the error
error C2678: binary '++' : no operator found which takes a left-hand operand
of type 'A' (or there is no acceptable conversion)
could be 'const B operator ++(B &,int)'
while trying to match the argument list '(A, int)'
Vladimir Grigoriev