Reducing code duplication between operator= and the copy constructor
I have a class that requires a non-default copy constructor and assignment operator (it contains lists of pointers). Is there any general way to reduce the code duplication between the copy constructor and the assignment operator? There's no "general way" for writing custom copy constructors and assignment operators that works in all cases. But there's an idiom called "copy-&-swap": class myclass { ... public: myclass(myclass const&); void swap(myclass & with); myclass& operator=(myclass copy) { this->swap(copy); return *this; } ... }; It's useful in many (but not all) situations. Sometimes