Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'd like to see an example of a function name being ignored in a nested-name-specifier

Foot note (33) in page 53 of N4140:

Lookups in which function names are ignored include names appearing in a nested-name-specifier, an elaborated-type-specifier, or a base-specifier.

like image 562
Ayrosa Avatar asked Mar 18 '23 05:03

Ayrosa


1 Answers

namespace A
{
    void std();
    void foo()
    {
        std::cout << "Hello World"; // (1)
    }
};

In (1), std cannot name a function, thus the function A::std is ignored during lookup, and the code compiles.
This rule is explicitly mentioned in [basic.lookup.qual]/1:

If a :: scope resolution operator in a nested-name-specifier is not preceded by a decltype-specifier, lookup of the name preceding that :: considers only namespaces, types, and templates whose specializations are types.

Another example from the list includes

class A : B {};

Here, B cannot designate a function, thus any functions called B are ignored during lookup. Same goes for

class A a;

Where A cannot name a function.

like image 93
Columbo Avatar answered Apr 27 '23 08:04

Columbo