如何使用模板初始化类中的静态成员数组
How to initialize static member array in class with template
可能的重复项:
我必须在哪里以及为什么必须放置"模板"和"类型名称"关键字?
#include <iostream>
using namespace std;
template <class T>
class Test
{
union obj
{
union obj* next;
int num;
};
static const int SZ=3;
static obj* volatile list[SZ];
};
template <class T>
Test<T>::obj* volatile
Test<T>::list[SZ]=
{
0, 0, 0
};
int main()
{
return 0;
}
使用g ++,我得到的错误是:
18|错误:在"*"标记之前进行预期的构造函数、析构函数或类型转换
在
成员定义中Test<T>::obj*
之前添加关键字 typename。
相关文章:
- 如何在C++函数中声明静态 2D 数组?
- 从另一个静态常量数组初始化静态常量数组(只需少量计算)
- 初始化在类类型 #define 中定义的非静态成员数组,不带默认 ctor
- C 指针可以指向字符串文字的静态成员数组
- 如何定义模板类专业化的静态constexpr数组成员
- 在gcc 4.8中初始化静态constexpr成员数组
- 如何将静态 const 数组声明和初始化为类成员
- 初始化私有成员静态常量数组
- 将静态成员数组初始化为零
- 如何使用模板初始化类中的静态成员数组
- 在静态const成员数组中键入将char强制转换为字符串的类型
- 如何用函数的结果初始化静态成员数组
- 带有序列的静态(成员)数组的优雅初始化
- c++ const静态成员数组初始化
- 是否可以动态初始化静态成员数组?
- 非静态数据成员(数组)的使用无效
- 在静态成员数组定义中对自身使用sizeof操作符
- 方法中使用的静态模板成员数组sizeof
- 初始化非静态成员数组
- 使用静态char*数组成员的模板特化,在多个单元中实例化