C++ requires create constructor of copies for assignment one instance to another instance. For example:
my_class a = b; It's wrong if I would implied copying, because it works as assignment of the address. Therefore, if I change a, b will be changed too. So, I should create constructor of copy:
my_class(const my_class &obj); It seems as obvious thing and rest is going without saying, but I have gotten a doubt, when I found out about overload operators:
my_class operator=(my_class obj); Turns out that I could use it as assignment and I don't have to use constructor of copies. Is that right? However, why assignment that is placed in the definition of operator= works as copying.
my_class a = b;the actual object is copied. If you havemy_class& a = b;then that's another matter.type name = valueyou are never doing assignment. You are initializingnameand will always be calling a constructor.