CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

error LNK2001!!!事成后给500分决不食言

楼主ghiewa(阿漠)2003-12-02 19:58:54 在 VC/MFC / 基础类 提问

 
  头文件声明如下:  
  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

相关问题

  • [求助]"Socket error是怎么回事呀!!"(回贴即给分,决不食言)
  • 送分!!!!!!当天结帐,决不食言。
  • 给热心人加分,决不食言!
  • *****500分求解问题,决不食言!!!!!
  • 即刻给分,决不食言!!!!
  • 1000分大奉送!!!!!决不食言!
  • 1000分大奉送!!!!!决不食言!
  • <font color="#FF0000">在 Oracle 中怎样用触发器实现象 Access 一样的自动编号,别掺水,这事很紧急,请给出确实可用的代码,如果试过能行给300分,决不食言</font>
  • 500分,决不食言,求WDL的文档制作器
  • CSocket类怎样设置超时?(83分,决不食言)

关键词

  • .net
  • 模板
  • 函数
  • 文件
  • vector
  • vc
  • combination
  • iv
  • thiscall
  • error lnk2001

得分解答快速导航

  • 帖主:ghiewa
  • jiangsheng
  • yangrudy
  • dawndu
  • tigerfox
  • badguy2002

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo