T
TDH1978
I have a class where the default constructor is disabled, and the only
constructor takes one parameter. The construction of the object
depends on a condition:
if (cond)
A a(x);
else
A a(y);
The problem is that the object 'a' goes out of scope after the 'if'
statement, and I do not want to use pointers, like:
A* aptr;
if (cond)
aptr = new A(x)
else
aptr = new A(y);
Is there a more elegant solution?
constructor takes one parameter. The construction of the object
depends on a condition:
if (cond)
A a(x);
else
A a(y);
The problem is that the object 'a' goes out of scope after the 'if'
statement, and I do not want to use pointers, like:
A* aptr;
if (cond)
aptr = new A(x)
else
aptr = new A(y);
Is there a more elegant solution?