P
P
Pavel2015-10-18 19:42:09
C++ / C#
Pavel, 2015-10-18 19:42:09

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;
}

in visual studio, it immediately highlights y1 as an error for me, writes about "ambiguous symbol". I can't understand where it takes y1 as double from. in theory, all variables, as they explained to me, are visible only in this file and do not go to the export table during compilation ... But why does it not allow me to create y1 ???

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stanislav Makarov, 2015-10-18
@rusbaron

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.

V
Vitaly, 2015-10-18
@vt4a2h

Where can I see reserved variable names?

Here: en.cppreference.com/w/cpp/keyword.
But your question is not about reserved names and not about dependencies, but about the rules for looking up names in C++. Move in that direction.

K
Konstantin, 2015-10-18
@Drakonn

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 question

Ask a Question

731 491 924 answers to any question