why can't we overload assignment '=' operator as a friend function

I just came through this concept,from thinking in c++ and from google what I understood is like copy constructor , if we do not create any =operator assignment overloading , the compilers provides one, and we write some code like

1
2
ClassTry A, B;
A=B;


it will do memberwise copy of B to A. and assignment operator will get called implicitly by the compiler. Can someone please give some more explanation or correct me if I am wrong ?
any help .. please ?
What kind of variable is ClassTry?
Yes, that is correct. Now A has what ever B has, but B doesn't have what ever A had.
The default copy constructor only does a shallow copy - this can be bad, particularly if you have dynamically allocated memory.

See shallow copy vs. deep copy
http://www.learncpp.com/cpp-tutorial/912-shallow-vs-deep-copying/

This page might be helpful too.
http://www.learncpp.com/cpp-tutorial/911-the-copy-constructor-and-overloading-the-assignment-operator/
Topic archived. No new replies allowed.