error LNK2019: unresolved external symbol


引用模板类时,出现下面错误

error LNK2019: unresolved external symbol "public: __thiscall CImageSegment<short>::CImageSegment<short>(void)" (??0?$CImageSegment@F@@QAE@XZ) referenced in function "public: void __thiscall CSegmentImgTestDlg::OnBnClickedButtonSeg(void)" (?OnBnClickedButtonSeg@CSegmentImgTestDlg@@QAEXXZ)
1>K:\myProgram\testFile\SegmentImgTest\Debug\SegmentImgTest.exe : fatal error LNK1120: 1 unresolved externals。

 

看起构造函数的声明和定义都存在,但是依然发生链接错误。

查网参考http://zhidao.baidu.com/question/417632742.html

模板类IDE不支持分离定义的。如果.h和.cpp是分离的需要 include .cpp文件,这样在其他文件中包含.cpp文件觉得怪怪的。

第二种解决方案:

.cpp 中添加宏定义,将.cpp 作为一个宏定义。在.h文件中包含这个宏定义。

#ifndef _IMAGESEGMENT_CPP_
#include "ImageSegment.cpp"
#endif

///.cpp 文件

#include "stdafx.h"
#ifndef _IMAGESEGMENT_CPP_
#define  _IMAGESEGMENT_CPP_
#include "ImageSegment.h"

template <class ImageType >
CImageSegment<ImageType>::CImageSegment(void)
{
}
template <class ImageType >
CImageSegment<ImageType>::~CImageSegment(void)
{
}

template <class ImageType >
int CImageSegment<ImageType>::GetVolumeImageROI( ImageType *pBWVol, int nWidth, int nHeight, int nSlice, POINT *leftTop, POINT *bottomDown )
{
   ......................
    return 0;

}

#endif

/

。h文件

#include <Windows.h>
template <class ImageType>
class CImageSegment
{
public:
    CImageSegment(void);
    ~CImageSegment(void);
public:
    int  GetVolumeImageROI(ImageType *pBWVol, int nWidth, int nHeight, int nSlice, POINT *leftTop, POINT *bottomDown );
public:
    int BWimage(ImageType *pSrcVol, double dValMin,double dValMax,const double thredshold, long nPixelNum,ImageType *pBWVol);


};

 //the IDE is not support template class definision in different file.

#ifndef _IMAGESEGMENT_CPP_
#include "ImageSegment.cpp"
#endif

///


还有一种方法:

把Cpp文件改为inl(内联)文件

并在.h 中包含#include “***.inl”




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值