Topic: User-defined assignment op overrides default?
Author: jason@cygnus.com (Jason Merrill)
Date: Fri, 3 Jun 1994 20:05:30 GMT Raw View
>>>>> Edgar Holcomb <holcomb@wg.com> writes:
> Two of the compilers I use (Centerline and Lucid) do not complain. It
> seems that thay supply the "default" memberwise assignment operator.
> However, the third compiler that we use, gcc, complains that this
> operator does not exist.
This is a bug in g++ 2.5.8. It will be fixed in 2.6.0.
Jason
Author: holcomb@wg.com (Edgar Holcomb)
Date: 03 Jun 1994 15:05:02 GMT Raw View
I have a class, ObjectID. It represents an snmp object id, which is a string
in dotted octet notation, such as "1.3.6.1.2.1.16". This example has seven
terms.
The class is structured like this:
class ObjectID
{
public:
ObjectID();
ObjectID( const String& strOid );
...
ObjectID& operator =( const String& strOid );
private:
int _numTerms;
String _strOid;
...
};
Note that I define only one assignment operator, which take a String reference.
I do this because I need to parse the string to make sure it's a valid id, and
also to count the terms in the string.
Note that I do *not* define the (default?) assignment operator,
ObjectID& operator =( const ObjectID& other )
because I don't need to do anything special here - I can simply rely on
member-wise copy (assume that class String defines assignment).
Given the following fragment:
ObjectID oid1( "1.3.6.1.2.1.16" );
ObjectID oid2;
oid2 = oid1;
Two of the compilers I use (Centerline and Lucid) do not complain. It seems
that thay supply the "default" memberwise assignment operator. However, the
third compiler that we use, gcc, complains that this operator does not exist.
Question: if I define my one assignment operator, which is not the "default"
assignment (i.e. taking a reference to an object of the same class type), must
I also define this "default" operator?
Thanks in advance!
-Edgar