Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unqualified lookup and (maybe-)dependent base classes

Tags:

c++

Consider the following program:

template <typename T>
struct t
{
    struct base { void f1(); };
    struct derived : base
    {
        void f2()
        {
            f1();
        }
    };
};

In derived::f2, unqualified lookup is used to find f1. Will base be searched? Will base::f1 be found? Is base a dependent type?

Please substantiate your answers with quotes from the standard.

like image 230
avakar Avatar asked Sep 24 '10 14:09

avakar


1 Answers

Yes, base is dependent so f1 is not found. In C++03 this was clearified by the addition 14.6.1/2d (which did not exist in C++98) and in C++0x this is directly stated by 14.6.2.1/6 (n3126).

Dependency of it is important, because the following is possible

// for T = int, f1 does not exist.
template<> struct t<int>::base { };
like image 116
Johannes Schaub - litb Avatar answered Nov 16 '22 18:11

Johannes Schaub - litb