error LNK2001!!!事成后给500分决不食言
头文件声明如下:
template<class T> class combination{
public:
……
bool have_next_combination();
void get_next_combination(output_vector &)const;
T* operator[](const unsigned&);
public:
//constructing function
combination();
combination(const input_vector &);
……
};
调用如下:
#include "combination.H"
#include <time.h>
#include <iostream.h>
//using namespace std;
void main()
{
combination<int>::input_vector iv;
combination<int>::output_vector ov;
iv.resize(11);
iv[0]=2;iv[1]=3;iv[2]=5;iv[3]=1;iv[4]=2;iv[5]=4;iv[6]=3;iv[7]=4;iv[8]=1;iv[9]=2;iv[10]=2;
combination<int> c(iv);
c[0][0]=3;c[0][1]=4;
c[1][0]=1;c[1][1]=34;c[1][2]=76;
c[2][0]=2;c[2][1]=3;c[2][2]=67;c[2][3]=34;c[2][4]=23;
c[3][0]=9;
c[4][0]=19;c[4][1]=29;
c[5][0]=90;c[5][1]=91;c[5][2]=94;c[5][3]=92;
c[6][0]=93;c[6][1]=59;c[6][2]=9;
c[7][0]=95;c[7][1]=9;c[7][2]=90;c[7][3]=95;
c[8][0]=950;
c[9][0]=39;c[9][1]=49;
c[10][0]=19;c[10][1]=569;
while(c.have_next_combination())
{
c.get_next_combination(ov);
……
}
……
}
运行报错:
--------------------Configuration: template_produce_combination - Win32 Debug--------------------
Compiling...
combination.cpp
Linking...
main.obj : error LNK2001: unresolved external symbol "public: void __thiscall combination<int>::get_next_combination(class std::vector<int,class std::allocator<int> > &)const " (?get_next_combination@?$combination@H@@QBEXAAV?$vector@HV?$allocator@H@
std@@@std@@@Z)
main.obj : error LNK2001: unresolved external symbol "public: bool __thiscall combination<int>::have_next_combination(void)" (?have_next_combination@?$combination@H@@QAE_NXZ)
main.obj : error LNK2001: unresolved external symbol "public: int * __thiscall combination<int>::operator[](unsigned int const &)" (??A?$combination@H@@QAEPAHABI@Z)
main.obj : error LNK2001: unresolved external symbol "public: __thiscall combination<int>::combination<int>(class std::vector<unsigned int,class std::allocator<unsigned int> > const &)" (??0?$combination@H@@QAE@ABV?$vector@IV?$allocator@I@std@@@std@
@@Z)
Debug/template_produce_combination.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
template_produce_combination.exe - 5 error(s), 0 warning(s)
问题点数:100、回复次数:11Top
1 楼broadoceans(broadoceans)回复于 2003-12-02 20:10:21 得分 0
可以看一下你的combination.cpp吗?
Top
2 楼jiangsheng(蒋晟.Net[MVP])回复于 2003-12-02 20:14:19 得分 20
templates should be implemented in header filesTop
3 楼yangrudy(*Start From Scratch)回复于 2003-12-02 20:15:04 得分 5
你在Project->setting->link中添加上你用到的lib文件试试~~~~~~~~~
Top
4 楼crystal_heart(笑看风云)回复于 2003-12-02 20:35:33 得分 0
upTop
5 楼dawndu(东南飞)回复于 2003-12-02 20:39:54 得分 5
jiangsheng(蒋晟.Net)说的对,vc6的规矩,模板类都要写到头文件里,是这个原因的话
别给分我
Top
6 楼ydfok(发芽的石头)回复于 2003-12-02 20:53:32 得分 0
兄弟不会仅仅申明,而没有实现吧?Top
7 楼tigerfox(风之力:=Doing.浪淘沙)回复于 2003-12-02 21:06:09 得分 60
VC不支持模板函数导出的。
在VC中,只你用到的模板函数才能被编译,否则不被编译
最好将代码全部写到头文件中。Top
8 楼badguy2002(风一样的男孩)回复于 2003-12-02 21:58:32 得分 10
你不会把模板类的声明和定义分别写在.h和.cpp文件了吧,要是这样好像不行啊,Vc好像不支持这样的,你试着把定义和声明都写在.h文件里面看看Top
9 楼nonocast(如果没有如果)回复于 2003-12-02 22:20:00 得分 0
添加lib了吗?
把程序发给我
我帮你看看
o_nono@163.netTop
10 楼hdqqq(小西瓜)回复于 2003-12-02 22:25:55 得分 0
从你现在的代码看
bool have_next_combination();
void get_next_combination(output_vector &)const;
这两个函数你是光声明,没有定义,所以连接时错误.
Top
11 楼ghiewa(阿漠)回复于 2003-12-04 20:57:20 得分 0
剩余分不知道怎么给出 郁闷Top




