I can’t understand why this works:
#include <iostream>
using namespace std;
int main(){
signed long int count = 1;
//...
count++;
return 0;
}
And yet if I move the identifier declaration (limit) to the start of the script (just after the using namespace), it fails to compile with the error “count undeclared (first use in this function)” – highlighting the line ‘count++;’.
Alternatively, Codepad results in the following error:
In function 'int main()':
Line 16: error: reference to 'count' is ambiguous
compilation terminated due to -Wfatal-errors.
Thanks,
Will.
You probably have a collision between your
countvariable andstd::count.You should not use
using namespace stdas this places everything from the standard library into the global namespace and names will soon collide.Use specific using lines such as
using std::cin;instead.