c++ - 函数模板 : typename declaration

标签 c++ templates

在 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/

相关文章:

c++ - 用于 C++ 的颜色图库,可将给定值转换为红色、绿色和蓝色值

python - 混淆将 c++ 库包装到 python

python - Django AllAuth 自定义模板不被识别

c++ - 链表帮助c++

c++ - 在 C++ 中使用 libtiff 写入图像时出现问题,在 TIFFScanlineSize 中出现整数溢出

c++ - 在 Ubuntu 上链接 OpenCV 2.3.1

c++ - C 与 C++ 中的指针

c++ - Win32 C/C++ 从字节数组中读取 BMP 宽度和高度

javascript - 如何让一个div出现,然后一直向右滑动,然后慢慢淡出?

c++ - 从模板参数中提取 simd vector 长度以用于本地类型