C ++ / GCC - Why is this compiler

Coding tonight (I understand this is Valentine's Day) and came across something strange ...

I have the following line:

std:;cout << freqs[summations[i]] / 1000 * 10 << std::endl;

It compiles. However, if I do this, it will not compile.

std;;cout << freqs[summations[i]] / 1000 * 10 << std::endl;

I do not have strict properties in my compilation line. However, I would not have thought that GCC would allow this to compile and output. Why is this?

+3
source share
3 answers

The first line contains a label std:followed by a null operator - a semicolon.

The rest uses cout << ...and means that you must have using namespace std;or using std::cout;or something similar in essence.

The second uses an identifier stdthat is not defined.

+5

std:; , .

+6

std:; - . .

, . , , std:: endl ( std endl, ). . :

ADL only occurs if the normal search for an unqualified name does not find a suitable member function. In this case, other namespaces are not taken into account in the ordinary search, you can find where the set of namespaces to be searched depend on the types of the function arguments. In particular, the set of declarations opened during ADL, and considered to resolve the name function, is the union of the declarations found by a regular search with the declarations found by searching the set of namespaces associated with the argument types of the function.

0
source

All Articles