不合格的查找和(可能)依赖的基类

ava*_*kar 5 c++

考虑以下程序:

template <typename T>
struct t
{
    struct base { void f1(); };
    struct derived : base
    {
        void f2()
        {
            f1();
        }
    };
};
Run Code Online (Sandbox Code Playgroud)

derived::f2,使用非限定查找来查找f1.会base被搜查?会base::f1被发现?是base一种依赖型?

请使用标准中的引用来证实您的答案.

Joh*_*itb 8

是的,base是依赖所以f1没有找到.在C++ 03中,这通过添加 14.6.1/2d(在C++ 98中不存在)和在C++ 0x中被14.6.2.1/6清除,这由(n3126)直接说明.

它的依赖性很重要,因为以下是可能的

// for T = int, f1 does not exist.
template<> struct t<int>::base { };
Run Code Online (Sandbox Code Playgroud)