Declaring an object in an if block
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" -
Code:
if (input == 1) {
ClassA my_instance(int a);
} else {
ClassA my_instance(string b);
}
However, in that case, "my_instance" will not be accessible by the code that follows.
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