I do not understand 3.4 / 2 in the Standard

I do not understand 3.4 / 2 in the standard:

A name “misrepresented in the context of an expression” is considered an unqualified name in the area where the expression is found.

What if the name is defined as N::ibelow?

#include <iostream>

namespace N { int i = 1; }

int main()
{
    int i = 0;

    std::cout << N::i << '\n';
}

The qualified name N::idoes not appear in the area where it is N::ifound, i.e. not visible in main () and global areas!

+4
source share
2 answers

To extend the comment from @JerryCoffin, the rules for qualified searches are:

3.4.3 Qualified Name Search [basic.lookup.qual]

3 , declarator quali-id, , ; , , .

:

#include <iostream>

struct N { enum { i = 1 }; };

int main()
{
    std::cout << N::i << '\n'; // prints 1

    struct N { enum { i = 0 }; };

    std::cout << N::i << '\n'; // prints 0
}

Live.

0

:: , . , N::i, N, , N, i. !

N . §3.3.10: " ".

, (N) , , ( , ) . , :

#include <iostream>

struct N { enum { i = 1 }; };

int main()
{
    int N = 3;
    std::cout << N::i << '\n'; // prints 1
    std::cout << N << '\n'; // prints 3

    struct N { enum { i = 0 }; };

    std::cout << N::i << '\n'; // prints 0
}

http://coliru.stacked-crooked.com/a/9a7c9e34b1e74ce7

. 3.3.4/1:

:: (5.1), -, , . :: decltype, , , :: , , . , , .

0

Source: https://habr.com/ru/post/1546438/


All Articles