Answer the question
In order to leave comments, you need to log in
Where can I see reserved variable names?
Good evening! Recently, I started learning C++, going to courses. The courses covered the topic about namespace and external dependencies, I decided to understand this in more detail, I wrote a test code. An example is below.
#include <iostream>
using std::cout;
using std::endl;
namespace
{
int y1, x1;
extern int x,y;
}
int main()
{
cout << y1 << endl;
cout << x << endl;
return 0;
}
Answer the question
In order to leave comments, you need to log in
Is the compiler or linker throwing an error?
If the compiler, then this is rather strange, try to output not y1, but a string to make sure that the problem is in y1.
If it's a linker, then you probably have y1 as an external link from another file. That's right, nothing will be exported from an unnamed namespace, but this does not mean that the name from this space will "override" the rest. Now, if you find ANOTHER y1 in a different compilation unit, and ALSO put it in an unnamed namespace, then everything will compile without problems.
Where can I see reserved variable names?
in each included *.h file, open it and see which macros and constants have already been used
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question