Why does the following code compiles, under g++, with out any warning or error?
The problem I see is that the variable x defined in the first line is accessible inside the if scope but in spite that it's redefined again.
int main() {
int x = 5;
std::cout << x;
if (true) {
int x = 6;
std::cout << x;
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…