Chinaunix首页 | 论坛 | 博客
  • 博客访问: 435401
  • 博文数量: 122
  • 博客积分: 3010
  • 博客等级: 中校
  • 技术积分: 1538
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-17 11:10
文章分类

全部博文(122)

文章存档

2011年(1)

2008年(86)

2007年(35)

我的朋友

分类: C/C++

2008-04-01 22:43:56

   
    今天动手编程,在用template时出现以下问题:

    graph.h:274: error: too few template-parameter-lists

    原来这是一个gcc版本导致的问题,我参照的是某先人97年的程序,我的4.1.3版本的gcc却不认识了。找了一圈,在这里找到了答案:

    以下将这个例子摘录:

#include <iostream>
using namespace std;

template <typename T>
class testClass
{
public:
static int _data;
};

int testClass<int>::_data = 1;

int main()
{
cout << testClass<int>::_data << endl;
return 0;
}


    在g++-3.3以下的版本可以编译通过
    而在3.4以后的版本必须写作 template int testClass::_data = 1;
阅读(3534) | 评论(2) | 转发(1) |
给主人留下些什么吧!~~

guhn1212016-12-02 09:34:22

chinaunix网友:写成 template <> int testClass::_data = 1;就可以了 不然就改变原来程序的意思了

新手求教! template  和 template <> 有什么区别?

回复 | 举报

chinaunix网友2008-12-24 15:03:56

写成 template <> int testClass::_data = 1;就可以了 不然就改变原来程序的意思了