Can anybody explain me Assignment Operator in below mention code. I have
Ques 1: Why that assignment operator return Reference Object [I know this is used for something like this c1 = c2 = c3, But how this is work]
Quest 2: I have created dynamic pointer tempName but I've not release the memory, so there is a memory leak. How I can resolve that. Or give me example if you have.
Quest 3: I have assigned tempName in name, so name is pointing to tempName if I delete tempName before the return, then what will happen.
Contact& operator=( const Contact& rhs ) { char* tempName = new char[ strlen( rhs. name ) + 1] ; delete[ ] name; name = tempName; strcpy( name, rhs. name ) ; age = rhs. age; return *this; }