VC++.NET2003中的模板问题?

Genius125 2003-09-29 10:08:43
//Test.h
#include <iostream>
using namespace std;
template<class Type>
class Test
{
Type data;
public:
Test(Type value)
{
data=value;
}
void Print();
};




//Test.cpp

#include "Test.h"

template<class Type>
void Test<Type>::Print()
{
cout<<data<<endl;
}



//Main.cpp
#include <iostream>
#include "Test.h"
using namespace std;

int main()
{
int a=10;
Test<int> test(10); //此行代码无错
test.Print(); //次行代码有错:LNK2019:无法调用Print()
return 0;
}


急救!!!!!!!!!!!!!!!!!!!!!!!!


...全文
43 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Realdodo 2003-10-01
  • 打赏
  • 举报
回复
test.h的首行应有
#param once
蒋晟 2003-09-29
  • 打赏
  • 举报
回复
C++的模板实现都是放在头文件里面的
zcpro 2003-09-29
  • 打赏
  • 举报
回复
同意jiangsheng(蒋晟.Net),模板类只能放在一个文件里,不能拆成.h和.cpp两个文件,一般都放在.h里。

7,540

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 VC.NET
社区管理员
  • VC.NET社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧