考虑以下代码:
struct A
{
void foo( const char * ) { cout << __PRETTY_FUNCTION__ << endl; }
A & operator = ( const A & ) { cout << __PRETTY_FUNCTION__ << endl; return * this; }
};
struct B : public A
{
void foo( const char * ) { cout << __PRETTY_FUNCTION__ << endl; }
A & operator = ( const A & other ) { cout << __PRETTY_FUNCTION__ << endl; return * this; }
};
然后当我们调用这个成员时:
B b;
b.foo( "hehe" );
b = b;
将打印:
void B::foo( const char *)
A& A::operator=(const A&)
问题:为什么 B::foo 隐藏了 A::foo,而 B::operator= 没有?