可能重复:
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 :: obj *'帮助之前添加'typename'? –
2012-04-08 04:12:57
如果你在类之外声明该联合,它是否工作? – rutgersmike 2012-04-08 04:13:55
两个都没问题,但我只知道后者。 – prehistoricpenguin 2012-04-08 07:15:39