考虑以下程序:
template <typename T>
struct t
{
struct base { void f1(); };
struct derived : base
{
void f2()
{
f1();
}
};
};
在derived::f2
中,非限定查找用于查找f1
。 base
会被搜索吗? base::f1
会被找到吗? base
是依赖类型吗?
请引用标准来证实您的答案。
最佳答案
是的,base
是相关的,因此找不到 f1
。在 C++03 中,addition 明确了这一点。 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 { };
关于c++ - 非限定查找和(可能)依赖的基类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3787845/