I have a declaration like this (from a .h file):
Code:
class emlMsg
{
public:
emlMsg(string From, int NumAddrs, string Addrs[], string To, string Sbj, string Msg)
{init(From, NumAddrs, Addrs, To, Sbj, Msg);}
void init(string From, int NumAddrs, string Addrs[], string To, string Sbj, string Msg);
emlMsg& operator = (emlMsg& rhs){this->init(rhs.from, rhs.numAddrs, rhs.addrs,
rhs.to, rhs.sbj, rhs.msg); return *this;}
~emlMsg();
void dump(char* prefix="");
string from;
string* addrs;
string to;
string sbj;
string msg;
int numAddrs;
};
(note the bolded declaration) that is initialized and has an operator = defined through the function init and has a destructor defined in a .cpp file thusly:
Code:
void emlMsg::init(string From, int NumAddrs, string Addrs[], string To, string Sbj, string Msg)
{
from= From;
to= To;
sbj= Sbj;
msg= Msg;
numAddrs= NumAddrs;
addrs= new string[NumAddrs];
for(int i= 0; i < NumAddrs; i++)addrs[i]= Addrs[i];
dump("emlMsg::init: New Message");
}
emlMsg::~emlMsg()
{
theLog.Write(LogDebug, "emlMsg::~emlMsg: deleting addrs\n");
delete addrs;
theLog.Write(LogDebug, "emlMsg::~emlMsg: done deleting addrs\n");
}
(Note bolded assignment and delete statement)
Three questions:
1. When I delete addrs in ~emlMsg, I get an abort signal. Any idea what I could be doing wrong here?
2. When I declare the addrs like this:
in the .h file, the compiler says:
error: incompatible types in assignment of 'std::string*' to 'std::string [0u]
What's wrong here?
3. A string assignment operator is overloaded, right, so string1=string2 actually copies from string2 to string1 instead of just assigning pointers?
I know I should be using vectors and will probably change over, but I'm really curious (not to mention frustrated) about this.
TIA,
anw