可能重复:
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
答案 0 :(得分:3)
在成员定义中添加Test<T>::obj*
之前的关键字typename。