shared_ptr<ObjectType> myNewObject = CreateObjectType();
MyNewObject->Initialise(a, b, c, d, e, f);
Each class has an abstract interface in the header and an 'Impl in the .cpp file that derives from the abstract interface. Thus, for example:
// Abstract interface class Object{public: virtual void Initialise(...) = 0; // THROWS};// Create methodshared_ptr<Object> CreateObject();
and in the .cpp:
class ObjectImpl: public SharedBase<ObjectImpl>, public Object{public: ObjectImple() : A(0), B(0), C() {} virtual void Initialise(...); // THROWSprotected: // Not logically possible to copy or duplicate ObjectImpl(const ObjectImpl&); ObjectImpl& operator = (const ObjectImpl&);private: A, B, C, etc...};... implementation ... followed by:shared_ptr<Object> CreateObject(){ return SharedObject<ObjectImpl>::Create();}
(SharedObject is a simple class that enforces non-copyable behavior and boost::enable_shared_from_this)
The advantage to me here is that I can modify the impl without having to re-compile everything that includes the abstract interface. By only ever initialising basic types in my constructor (assigning default values) and by using exceptions rather than return codes alongside smart pointers, I'm much better protected from the complexities of clean-up when things go wrong.
On the level of general principle then, I *never* allocate resources in a constructor and by using smart pointers I never have to implement a destructor either.