I know that we can directly assign same class objects in C++,but what actually happen behind the scene?
Asked
Active
Viewed 365 times
0
-
The class' `operator=` is called? E.g for `a = b` (where `a` is an object) then `a.operator=(b)` will be called. – Some programmer dude Jul 28 '17 at 07:54
1 Answers
2
There's something called "default copy-constructor" and "default assignment-operator". Unless you overload these methods in the class, the default behavior is that all non-static members of the class are copied one-by-one from the source to the target class.
A little more: This includes pointers, btw. Which is why you generally should overload these operators and follow the rule of three if you have pointers as members.

The Quantum Physicist
- 24,987
- 19
- 103
- 189