Hi, I am trying to initialize an object in an if block and make it accessible to the rest of my program without success. For example:
I want to use different overloaded constructors of ClassA depending on user input, stored in "input" -
However, in that case, "my_instance" will not be accessible by the code that follows.Code:if (input == 1) { ClassA my_instance(int a); } else { ClassA my_instance(string b); }
Is there any way I can declare the variable first, outside of the if block, without actually creating the object, then create the object in the if block?
Thank you very much for your help