Z
zqhpnp
class String
{
public:
String& operator=(const String& str);
private:
char* pdata;
}
String& String:perator=(const String& str)
{
if(this==&str)
return;
delete[] pdata;
pdata=new char[strlen(str.pdata)+1];
if(pdata==0)
return;
strcpy(pdata,str.pdata);
return *this;
}
str.pdata seem to be invalid,but the compiler(VC 6.0) dosen't report
errors.Why the object pointed by this pointer can access the
object's(referrenced by str) member pdata.Whether we can do like that
in specific functions(copy constructor...?).
Who can give me an answer? Thanks in advance.
{
public:
String& operator=(const String& str);
private:
char* pdata;
}
String& String:perator=(const String& str)
{
if(this==&str)
return;
delete[] pdata;
pdata=new char[strlen(str.pdata)+1];
if(pdata==0)
return;
strcpy(pdata,str.pdata);
return *this;
}
str.pdata seem to be invalid,but the compiler(VC 6.0) dosen't report
errors.Why the object pointed by this pointer can access the
object's(referrenced by str) member pdata.Whether we can do like that
in specific functions(copy constructor...?).
Who can give me an answer? Thanks in advance.