Vladimir Grigoriev
2009-12-18 14:09:34 UTC
Let consider the following code
struct A
{
A( int i = 0 ): x( i ) {}
int x;
};
struct B: public A
{
B( int i = 0 ): A( i ), value( x ) {}
B( const B &rhs ): A( rhs ), value( x ) {}
B & operator =( const B &rhs )
{
A::operator =( rhs );
return ( *this );
}
int &value;
};
As you can see in the base class there is no an assignment operator defined
explicitly. However in the derived class there is explicit reference to the
assignment operator of the base class.
The problem is the following. When I use some non-Microsoft compiler it
issues an error for this code. However if I will include an assignment
operator in the base class explicitly the error dissapears.
The Microsoft compiler VC++ 2005 EE compiles the code without any error.
Is it a bug of the non-Microsoft compiler? May I specify explicitly an
assignment operator in a derived class when in a base class it is absent and
defined by default by a compiler? What does C++ standard say about this?
Also as you can see as for a copy constructor there is not such problem when
the code compiled with the non-Micosoft compiler.
Vladimir Grigoriev
struct A
{
A( int i = 0 ): x( i ) {}
int x;
};
struct B: public A
{
B( int i = 0 ): A( i ), value( x ) {}
B( const B &rhs ): A( rhs ), value( x ) {}
B & operator =( const B &rhs )
{
A::operator =( rhs );
return ( *this );
}
int &value;
};
As you can see in the base class there is no an assignment operator defined
explicitly. However in the derived class there is explicit reference to the
assignment operator of the base class.
The problem is the following. When I use some non-Microsoft compiler it
issues an error for this code. However if I will include an assignment
operator in the base class explicitly the error dissapears.
The Microsoft compiler VC++ 2005 EE compiles the code without any error.
Is it a bug of the non-Microsoft compiler? May I specify explicitly an
assignment operator in a derived class when in a base class it is absent and
defined by default by a compiler? What does C++ standard say about this?
Also as you can see as for a copy constructor there is not such problem when
the code compiled with the non-Micosoft compiler.
Vladimir Grigoriev