I'm trying to declare a variable in an if-else block as follows:
int main(int argc, char *argv[]) {
if (argv[3] == string("simple")) {
Player & player = *get_Simple();
} else if (argv[3] == string("counting")) {
Player & player = *get_Counting();
} else if (argv[3] == string("competitor")) {
Player & player = *get_Competitor();
}
// More code
}
But, I'm getting the following errors when I try to compile:
driver.cpp:38: error: unused variable ‘player’
driver.cpp:40: error: unused variable ‘player’
driver.cpp:42: error: unused variable ‘player’
driver.cpp:45: error: ‘player’ was not declared in this scope
Any ideas?