首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

关于类模板的解决办法

2012-05-20 
关于类模板的我在 megersort.h 文件里定义了template class ElementTypeclass MegerSort{public:void So

关于类模板的
我在 megersort.h 文件里定义了 

template <class ElementType>
class MegerSort
{
public:
void Sort(ElementType element[],int n);
private:
void Msort(ElementType element[],ElementType tmp[],int left,int right);
void Meger(ElementType element[],ElementType tmp[],int lpos,int rpos,int rightend);
};

我在main.cpp 里面包含了megersort.h文件


#include "MegerSort.h"
#include <iostream>
using std::cin;
using std::cout;
using std::endl;

int main()
{
MegerSort<int> M;
int tmp[10];
int i;
for(i=0;i!=10;++i)
cin>>tmp[i];
M.Sort(tmp,10);
for(i=0;i!=10;++i)
cout<<tmp[i]<<'\ ';
system("pause");
}

但是编译失败 

main.obj : error LNK2019: unresolved external symbol "public: void __thiscall MegerSort<int>::Sort(int * const,int)" (?Sort@?$MegerSort@H@@QAEXQAHH@Z) referenced in function _main
1>F:\数据结构\分治法\Debug\分治法.exe : fatal error LNK1120: 1 unresolved externals
1>

这个实在是搞不懂。

[解决办法]
你函数的实现呢?就申明了下没有实现搞什么?还有就是模板需要定义和实现放在一个文件里。

热点排行