the class in question doesn't actually require new allocation in the assignment, i actually just want it to reassign the pointer, but it's calling the destructor after the assignment, so it's deleting the newly assigned message from the asignee. (or at least i think that's what it's doing)
i'm having to trouble using the assignment operator. this class has specialized template descendants, but when i try to do the following:
Code:
//DATAID and CEID are Strings
secs2MsgItem<String>ID(DATAID);
report->addDatum(ID);
ID=secs2MsgItem<String>(CEID);
report->addDatum(ID);
i get " E2285 Could not find a match for 'secs2MsgItem<AnsiString>:perator =(secs2MsgItem<AnsiString>)'"
i even added a template assignment operator, but it's just not matching it in the base class. is it because the derived classes are specialized and this function isn't?
here's the c'tors, d'tor and the newly added assignment operator. anything bad sticking out at you?
Code:
// in header file
template<typename T> secs2MsgItem<T>& operator =(secs2MsgItem<T>&RHS)
{
delete[]message;
message = RHS.message;
RHS.message = 0;
return *this;
}
//in implementation file
__fastcall secs2MsgData::secs2MsgData() :
message(new char[2])
{
message[0]=1;
message[1]=0;
}
__fastcall secs2MsgData::secs2MsgData(char *_message) :
message(_message)
{
unsigned int l;
if(formatCode())
{
l = length();
}
else
{
l = headerLength()+((secsList*)this)->secsList::dataLength();
}
char *c = new char[l];
copychar(c,_message,l);
message =c;
}
__fastcall secs2MsgData::secs2MsgData(const secs2MsgData©)
{
unsigned int l=copy.length();
message = new char[l];
copychar(message,copy.getMsg(),l);
}
__fastcall secs2MsgData::~secs2MsgData()
{
if(message)
{
delete[]message;
}
}
secs2MsgData& secs2MsgData::operator =(secs2MsgData&RHS)
{
delete[]message;
message = RHS.message;
RHS.message = 0;
return *this;
}