Is this unqualified lookup in c++?

2019-06-09 15:11发布

问题:

    #include <iostream>
    namespace X
    {
        int k  = 8;
    }
    int main()
    {
        using namespace X;
        int  k = 0;


        std::cout << k;


        return 0;
    }

I am struggling to understand the difference between qualified and unqualified lookup, and how they deal with using namespace ; phrases

For now, I would like to make clear ?Here k causes qualified lookup right?

回答1:

It is unqualified name lookup:

For an unqualified name, that is a name that does not appear to the right of a scope resolution operator ::, name lookup examines the scopes as described below, until it finds at least one declaration of any kind, at which time the lookup stops and no further scopes are examined.

as k does not appear to the right of a scope resolution operator.



标签: c++ lookup