Re: C++ std::string tries to free() a not allocated pointer ?
Re: C++ std::string tries to free() a not allocated pointer ?
- Subject: Re: C++ std::string tries to free() a not allocated pointer ?
- From: Robert Schwalbe <email@hidden>
- Date: Thu, 19 Nov 2009 10:34:09 -0500
The class does have a copy constructor. It actually has several. I
omitted them because I didn't think they were relevant. I still
don't think they are. Here they are:
const SQLString & operator=(const char * s)
{
realStr = s;
return *this;
}
const SQLString & operator=(const std::string & rhs)
{
realStr = rhs;
return *this;
}
const SQLString & operator=(const SQLString & rhs)
{
realStr = rhs.realStr;
return *this;
}
While I am not a C++ language lawyer, I will contend that the above
are three different assignment operators (i.e. not copy constructors).
A copy constructor would have the following signature:
SQLString:: SQLString(const SQLString &inSQLString)
{
realStr = inSQLString.realStr;
}
And now I am going to contend that the first two routines probably never
get called. You probably really just want a couple of constructors:
SQLString::SQLString(const char * s) : realStr(s)
{
// replaces: const SQLString & operator=(const char * s)
}
SQLString::SQLString(const std::string &rhs) : realStr(rhs)
{
// replaces: const SQLString & operator=(const std::string & rhs)
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden