scalagator is 100% right.
To explain a bit more as to why, it has to do completely with the scope of the variables. And as your example shows, C++ is able to differentiate between same named variables in different scopes. When a conflict of these same named variables occurs, C++ will use the variable with the smallest scope by default.
To show another example of this, consider the following block of code:
#include <iostream>
int Number = 0;
void Initialize() {
constexpr BIG_NUMBER = 12;
int Number = BIG_NUMBER;
}
int GetNumber() { return Number; }
void main() {
Initialize();
std::cout << GetNumber() << std::endl;
}
When you run this code, you’ll get the same issue that you’re having with your own code. Despite the fact that you’re initializing a variable named Number to be 12, the Number that is received from GetNumber() will still be 0. This is because at the time of initilization, a new Number variable is created that lives only within te Initialize() method. Once it’s done, the local variable with 12 in it is gone. This leaves only the Number that is set to 0.
Scalagator already showed the fix for this. I just wanted to flesh out more as to the why.