在 GCC 上,下面给出了一个错误:no type named 'x' in 'struct Type'
在 VC++ 上,它提示 p
未声明
struct Type
{
static int const x = 0;
};
template <class T> void Func()
{
typename T::x * p; // p to be pointer
}
int main()
{
Func<Type>();
}
最佳答案
T::x
变成 Type::x
,这是一个 int
,不是类型。
你已经告诉编译器 T::x
使用 typename
命名类型.当Func<Type>
被实例化,T::x
不是类型,所以编译器报错。
关于c++ - 函数模板 : typename declaration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5734768/