Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Chapter 43. Pimpl judiciously > References - Pg. 78

78 C++ Coding Standards class Widget { // ... public: Widget& operator=( const Widget& ); private: T1 t1_; T2 t2_; }; In short, we cannot write operator= to give the strong guarantee or even the mini- mum required (basic) guarantee if T1 or T2 operations might fail in a way that is not reversible (see Item 71). The good news is that the following simple transformation always works to enable at least the basic guarantee for error-safe assignment, and usually the strong guarantee as long as the needed T1 and T2 operations (notably construction and destruction) don't have side effects: Hold the member objects by pointer instead of by value, preferably all behind a single Pimpl pointer. class Widget { // ... public: Widget& operator=( const Widget& );