inheritance and copy constructor conflict
before putting in a copy constructor, the static_casts in the == and < operators work without any problems.
class TypeCORD2R: public TypeCORD2C
{
public:
TypeCORD2R(string & data);
};
bool operator<(const TypeCORD2R & itemA, const TypeCORD2R & itemB);
bool operator==(const TypeCORD2R & itemA, const TypeCORD2R & itemB);
bool operator==(const TypeCORD2R & itemA, long itemB)
{
if(itemA.CID==itemB)
return true;
else
return false;
};
bool operator==(const TypeCORD2R & itemA, const TypeCORD2R & itemB){
return ((static_cast<TypeCORD2C>(itemA))==(static_cast<TypeCORD2C>(itemB)));
};
bool operator<( const TypeCORD2R & itemA, const TypeCORD2R & itemB){
return ((static_cast<TypeCORD2C>(itemA))<(static_cast<TypeCORD2C>(itemB)));
};
TypeCORD2R::TypeCORD2R(string & data):TypeCORD2C(data)
{
//no code needed, all work done by parent
}
However, once I introduce a copy constructor into TypeCORD2C as below, the static casts in the operators above all of a sudden become problems.
the error is:
error C2440: 'static_cast' : cannot convert from 'const TypeCORD2R' to 'TypeCORD2C'
No constructor could take the source type, or constructor overload resolution was ambiguous
any ideas?
class TypeCORD2C: public TypeBase
{
public:
long CID;
long RID;
float A[3];
float B[3];
float C[3];
TypeCORD2C(string & data);
TypeCORD2C(TypeCORD2C & cord2cIn);
friend class TypeCORD2R;
list<string> toLines();
};
bool operator==(const TypeCORD2C & itemA, const TypeCORD2C & itemB);
bool operator<(const TypeCORD2C & itemA, const TypeCORD2C & itemB);
bool operator==(const TypeCORD2C & itemA, long itemB)
{
if(itemA.CID==itemB)
return true;
else
return false;
};
bool operator==(const TypeCORD2C & itemA, const TypeCORD2C & itemB){
if(itemA.CID==itemB.CID)
return true;
else
return false;
};
bool operator<( const TypeCORD2C & itemA, const TypeCORD2C & itemB){
if(itemA.CID<itemB.CID)
return true;
else
return false;
};
TypeCORD2C::TypeCORD2C(TypeCORD2C & cord2cIn)
{
CID = cord2cIn.CID;
RID = cord2cIn.RID;
for (int i = 0; i<3 ; i++)
{
A[i] = cord2cIn.A[i];
B[i] = cord2cIn.B[i];
C[i] = cord2cIn.C[i];
}
}
TypeCORD2C::TypeCORD2C(string & data)
{
//do stuff
}

