Scope of variables in if statements
问题 I have a class that has no default constructor or assignment operator so it is declared and initialized within an if/else statement depending on the result of another function. But then it says that it is out of scope later even though both routes of the conditional will create an instance. Consider the following example (done with int just to illustrate the point): #include <iostream> int main() { if(1) { int i = 5; } else { int i = 0; } std::cout << i << std::endl; return 0; } Do variables