求助高手

    技术2022-05-12  3

    我自定义了一个类,如下所示:

    class CLine  : public CObject{public: CPoint m_pointFrom; CPoint m_pointTo; COLORREF m_colorLine; int m_nWidth;    CLine() {} CLine(POINT from,POINT to,COLORREF color,int width); CLine& operator=(CLine& line); void Serialize(CArchive& ar); void DrawLine(CDC* pDC); //CLine(){} virtual ~CLine(); DECLARE_SERIAL(CLine);};IMPLEMENT_SERIAL(CLine,CObject,1)

    具体的实现函数如下:

    CLine::~CLine(){}

    // CLine 成员函数CLine& CLine::operator =(CLine &line){ m_pointFrom=line.m_pointFrom; m_pointTo=line.m_pointTo; m_colorLine=line.m_colorLine; m_nWidth=line.m_nWidth; return *this;}void CLine::Serialize(CArchive &ar){ if(ar.IsStoring())  ar<<m_pointFrom<<m_pointTo<<m_colorLine<<m_nWidth; else  ar>>m_pointFrom>>m_pointTo>>m_colorLine>>m_nWidth;}void CLine::DrawLine(CDC *pDC){ CPen penNew,*ppenOld; penNew.CreatePen(PS_SOLID,m_nWidth,m_colorLine); ppenOld=pDC->SelectObject(&penNew); pDC->MoveTo(m_pointFrom); pDC->LineTo(m_pointTo); pDC->SelectObject(ppenOld);}CLine::CLine(POINT from, POINT to, COLORREF color, int width){        m_pointFrom=from;  m_pointTo=to;  m_colorLine=color;  m_nWidth=width;}

    编译的时候总是出现链接错误,如下所示:

    错误 19 fatal error LNK1169: 找到一个或多个多重定义的符号 D:/程序/c++2008/HT/Debug/HT.exe 1 HT错误 6 error LNK2005: "struct AFX_CLASSINIT _init_CLine" (?_init_CLine@@3UAFX_CLASSINIT@@A) 已经在 HT.obj 中定义 HTDoc.obj HT错误 12 error LNK2005: "struct AFX_CLASSINIT _init_CLine" (?_init_CLine@@3UAFX_CLASSINIT@@A) 已经在 HT.obj 中定义 HTView.obj HT错误 18 error LNK2005: "struct AFX_CLASSINIT _init_CLine" (?_init_CLine@@3UAFX_CLASSINIT@@A) 已经在 HT.obj 中定义 Line.obj HT错误 4 error LNK2005: "public: virtual struct CRuntimeClass * __thiscall CLine::GetRuntimeClass(void)const " (?GetRuntimeClass@CLine@@UBEPAUCRuntimeClass@@XZ) 已经在 HT.obj 中定义 HTDoc.obj HT错误 10 error LNK2005: "public: virtual struct CRuntimeClass * __thiscall CLine::GetRuntimeClass(void)const " (?GetRuntimeClass@CLine@@UBEPAUCRuntimeClass@@XZ) 已经在 HT.obj 中定义 HTView.obj HT错误 16 error LNK2005: "public: virtual struct CRuntimeClass * __thiscall CLine::GetRuntimeClass(void)const " (?GetRuntimeClass@CLine@@UBEPAUCRuntimeClass@@XZ) 已经在 HT.obj 中定义 Line.obj HT错误 3 error LNK2005: "public: static struct CRuntimeClass * __stdcall CLine::GetThisClass(void)" (?GetThisClass@CLine@@SGPAUCRuntimeClass@@XZ) 已经在 HT.obj 中定义 HTDoc.obj HT错误 9 error LNK2005: "public: static struct CRuntimeClass * __stdcall CLine::GetThisClass(void)" (?GetThisClass@CLine@@SGPAUCRuntimeClass@@XZ) 已经在 HT.obj 中定义 HTView.obj HT错误 15 error LNK2005: "public: static struct CRuntimeClass * __stdcall CLine::GetThisClass(void)" (?GetThisClass@CLine@@SGPAUCRuntimeClass@@XZ) 已经在 HT.obj 中定义 Line.obj HT错误 1 error LNK2005: "public: static class CObject * __stdcall CLine::CreateObject(void)" (?CreateObject@CLine@@SGPAVCObject@@XZ) 已经在 HT.obj 中定义 HTDoc.obj HT错误 7 error LNK2005: "public: static class CObject * __stdcall CLine::CreateObject(void)" (?CreateObject@CLine@@SGPAVCObject@@XZ) 已经在 HT.obj 中定义 HTView.obj HT错误 13 error LNK2005: "public: static class CObject * __stdcall CLine::CreateObject(void)" (?CreateObject@CLine@@SGPAVCObject@@XZ) 已经在 HT.obj 中定义 Line.obj HT错误 2 error LNK2005: "protected: static struct CRuntimeClass * __stdcall CLine::_GetBaseClass(void)" (?_GetBaseClass@CLine@@KGPAUCRuntimeClass@@XZ) 已经在 HT.obj 中定义 HTDoc.obj HT错误 8 error LNK2005: "protected: static struct CRuntimeClass * __stdcall CLine::_GetBaseClass(void)" (?_GetBaseClass@CLine@@KGPAUCRuntimeClass@@XZ) 已经在 HT.obj 中定义 HTView.obj HT错误 14 error LNK2005: "protected: static struct CRuntimeClass * __stdcall CLine::_GetBaseClass(void)" (?_GetBaseClass@CLine@@KGPAUCRuntimeClass@@XZ) 已经在 HT.obj 中定义 Line.obj HT错误 5 error LNK2005: "class CArchive & __stdcall operator>>(class CArchive &,class CLine * &)" (??5@YGAAVCArchive@@AAV0@AAPAVCLine@@@Z) 已经在 HT.obj 中定义 HTDoc.obj HT错误 11 error LNK2005: "class CArchive & __stdcall operator>>(class CArchive &,class CLine * &)" (??5@YGAAVCArchive@@AAV0@AAPAVCLine@@@Z) 已经在 HT.obj 中定义 HTView.obj HT错误 17 error LNK2005: "class CArchive & __stdcall operator>>(class CArchive &,class CLine * &)" (??5@YGAAVCArchive@@AAV0@AAPAVCLine@@@Z) 已经在 HT.obj 中定义 Line.obj HT不知道是啥原因,希望有人指点迷津,本人感激不尽。


    最新回复(0)