我想用vc6.0编模板类(win32 console application)
//.h文件
template<class T>
class CTmp  
{
public:
T m_tDate;
public:
CTmp();
virtual ~CTmp();
void Show();};
//.cpp文件
#include "stdafx.h"
#include "iostream.h"
#include "Tmp.h"template<class T>
CTmp<T>::CTmp()
{
   m_tDate=185;
}
template<class T>
CTmp<T>::~CTmp()
{
}
template<class T>
void CTmp<T>::Show()
{
cout<<m_tDate<<endl;
}
//主函数
int main(int argc, char* argv[])
{
CTmp<int> tmp;
tmp.Show();
return 0;
}
连接出错
Error LNK2001: unresolved external symbol "public: virtual __thiscall CTmp<int>::~CTmp<int>(void)" (??1?$CTmp@H@@UAE@XZ)
请教问题出在哪里?拜谢!

解决方案 »

  1.   

    模板类的函数定义和实现只能放在同一个文件了(.h),只是vc 6 的一个缺陷,好像vc 7 解决了这个问题!
      

  2.   

    呵呵,在stdafx.h中加入#include<afxtmp.h>了吗?
      

  3.   

    错了,好像是
    #include <afxtmpl.h>
    我记不清了!
      

  4.   

    暂时用#include <atlbase.h>吧,应该有一个afx……我忘了
      

  5.   

    应该是#include <AfxTempl.h>
      

  6.   

    我试过了包含头文件的方法不行;将类定义和实现放在一起的方法可以
    感谢luofeitarget(靶子)  zjg751206(play程序)  的关注
    haowh(一个人走在黑黑的夜)  加15
    stoneyrh()  加5
    大家不介意吧