An easy way to do is to use std::unique_ptr:
std::unique_ptr<MyClass> myObjectPtr; if(useMyObject) myObjectPtr.reset(new MyClass(42)); if(myObjectPtr) myObjectPtr->method();
But note that it will require a heap allocation, which may be actually more expensive than an "empty" construction. To avoid the cost of heap allocation you can use boost::optional which is used similarly to a pointer, but in fact the storage for the object is allocated on the stack:
boost::optional<MyClass> myObject; if(useMyObject) myObject = MyClass(42); if(myObject) myObject->method();
As you see in any of the above cases, the code will be littered with conditions.
If you are allowed to change the MyClass I would suggest to just construct an "empty" object using the non-parametric constructor. You only need to construct the object into a state where it actually does nothing, but it should not crash the application if used. That empty construction should be cheap and it is only a one time cost anyway.
It would be even better if you can move the object into a scope where it is actually used and avoid the uninitialized/empty object altogether:
if(useMyObject) { MyClass myObject(42); // use the object here and nowhere else. }
if. Otherwise, how do you intend to use a non-constructed object?ifends. For example I could have anotherif ( useMyObject )later.MyClass *myObject...myObject = new MyClass(42)?