我在一个sdi程序中加入了一个类
, 没有使用其它lib class CPoint2D;class CPoint2D
{
public:
CPoint2D():x(0),y(0)
{
}
CPoint2D(double x, double y):x(x), y(y)
{
}
CPoint2D operator+( const CVector2D &v );
friend CPoint2D operator+( const CPoint2D &p1, const CPoint2D &p2 );
CVector2D operator-( const CPoint2D &v );
friend CPoint2D operator/( const CPoint2D &p, double scale );
double x;
double y;
};编译后出现如下 link error
DemoFaceChangedView.obj : error LNK2001: unresolved external symbol "class CPoint2D __cdecl operator+(class CPoint2D const &,class CPoint2D const &)" (??H@YA?AVCPoint2D@@ABV0@0@Z)DemoFaceChangedView.obj : error LNK2001: unresolved external symbol "class CPoint2D __cdecl operator/(class CPoint2D const &,double)" (??K@YA?AVCPoint2D@@ABV0@N@Z)
请问如何解决?谢谢
, 没有使用其它lib class CPoint2D;class CPoint2D
{
public:
CPoint2D():x(0),y(0)
{
}
CPoint2D(double x, double y):x(x), y(y)
{
}
CPoint2D operator+( const CVector2D &v );
friend CPoint2D operator+( const CPoint2D &p1, const CPoint2D &p2 );
CVector2D operator-( const CPoint2D &v );
friend CPoint2D operator/( const CPoint2D &p, double scale );
double x;
double y;
};编译后出现如下 link error
DemoFaceChangedView.obj : error LNK2001: unresolved external symbol "class CPoint2D __cdecl operator+(class CPoint2D const &,class CPoint2D const &)" (??H@YA?AVCPoint2D@@ABV0@0@Z)DemoFaceChangedView.obj : error LNK2001: unresolved external symbol "class CPoint2D __cdecl operator/(class CPoint2D const &,double)" (??K@YA?AVCPoint2D@@ABV0@N@Z)
请问如何解决?谢谢
就可以
#ifndef __CPOTNT2D_H__
#define __CPOINT2D_H__
//类声明
//...
#endif
原因就是:
1。你没有实现它;
2。虽然实现了,但你没有把它加入工程,以让编译器找到(例如CPP文件里)或者连接器找到(LIB或OBJ里)。