2 ms·
Personally I find that I don't ever use any of the more oop features of c++, especially copy constructors and assignment operators. If I'm in a situation where
by fallingfrog 9y ago
Personally I find that I don't ever use any of the more oop features of c++, especially copy constructors and assignment operators.
If I'm in a situation where I need to make a deep copy of an object, I need to ask myself why am I making an exact copy of a complex object with lots of internal pointers and state, an expensive operation. If I'm going to modify the result of the copy, perhaps what I should do is write a function that generates a new, different object based on the original one, in which case I would be passing in a const reference to the old object and maybe some other data about the new object I want to create. And if I'm not modifying the object, again why not just pass a const reference?
Also, the exact behavior of all these hidden functions can be really hard to figure out. Who wants to try and figure out how many times the copy and assignment operator is called if you do a=f(g(a)); and pass by value? No thanks.