missing ';' before ''template<''高手请进!

来源:百度知道 编辑:UC知道 时间:2024/05/16 01:06:12
test.h头文件的内容:
template<typename Type>
Type sum(Type a,Type b);//函数模版的声明

test.cpp文件的内容:
export template<typename Type>//前面加上export关键字
Type sum(Type a,Type b)
{
return a+b;
}//函数模版的定义

first.cpp文件的内容:
#include "test.h"
int main()
{
sum(2,3);
return 0;
}

我不知道你的编译环境是什么,我用VS2005编译了下,主要问题出在系统不支持export关键字,所以不加这个关键字反倒可以正常工作,下面是诊断信息:

c:\documents and settings\administrator\桌面\text.cpp(5) : warning C4237: 目前还不支持“export”关键字,但已保留该关键字供将来使用
c:\documents and settings\administrator\桌面\text.cpp(5) : error C2143: 语法错误 : 缺少“;”(在“'template<'”的前面)
c:\documents and settings\administrator\桌面\text.cpp(5) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int

我是门外汉,不大懂C++,你怎么不把test.cpp包含到first.cpp中?