Possible Duplicate:
Where and why do I have to put the “template” and “typename” keywords?
#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|error: expected constructor, destructor, or type conversion before '*' token
最佳答案
在 Test<T>::obj*
之前添加关键字 typename在成员的定义中。
关于c++ - 如何使用模板初始化类中的静态成员数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10060287/