On Sun, Oct 26, 2008 at 3:54 PM, Gopi Krishna Komanduri
<[EMAIL PROTECTED]> wrote:
[...]
> //=================================================== operator=
> Person& Person::operator=(const Person& p) {
>    if (this != &p) {  // make sure not same object
>        delete [] _name;                     // Delete old name's memory. // 
> why do I need to do this? cant I use the exisitng memory itself?

What if the currently assigned memory isn't big enough to hold the new data?

Why are you using arrays of char in C++ for strings anyway?

>        _name = new char[strlen(p._name)+1]; // Get new space
>        strcpy(_name, p._name);              // Copy new name
>        _id = p._id;                         // Copy id
>    }
>    return *this;    // Return ref for multiple assignment
> }//end operator= Thx,--Gopi



-- 
PJH

http://shabbleland.myminicity.com/sec

Reply via email to