当前位置: 代码迷 >> VC >> error LNK2019: 无法解析的外部符号,该如何解决
  详细解决方案

error LNK2019: 无法解析的外部符号,该如何解决

热度:1362   发布时间:2016-05-05 00:17:28.0
error LNK2019: 无法解析的外部符号
error LNK2019: 无法解析的外部符号 "protected: __thiscall CLine::CLine(void)" (??0CLine@@[email protected]),该符号在函数 "public: static class CObject * __stdcall CLine::CreateObject(void)" ([email protected]@@SGPAVCObject@@XZ) 中被引用 Elements.obj

我用的是VS2008.Net。下面是部分代码:
Elements.h文件的部分代码:
#pragma once

class CElement : public CObject  //CElement类的定义
{
DECLARE_SERIAL(CElement)
protected:
COLORREF m_Color;      
CRect m_EnclosingRect; 
int m_Pen;             
public:
virtual ~CElement();
virtual void Draw(CDC* pDC,CElement* pElement=0){}  
virtual void Move(CSize& aSize){}
CRect GetBoundRect(); 
virtual void Serialize(CArchive& ar); //类的串行化函数Serialize()
protected:
CElement(void);  
};

class CLine : public CElement  
{
DECLARE_SERIAL(CLine)
public:
~CLine(void);
virtual void Draw(CDC* pDC,CElement* pElement=0); 
virtual void Move(CSize& aSize);
CLine(CPoint Start,CPoint End,COLORREF aColor,int PenWidth); 
virtual void Serialize(CArchive& ar);
protected:
CPoint m_StartPoint; 
CPoint m_EndPoint;   
CLine(void);
};

Elements.cpp的部分代码:
// Elements.cpp : 实现文件

#include "stdafx.h"
#include <cmath>      
#include "Sketcher.h"
#include "Elements.h"
#include "OurConstants.h"

IMPLEMENT_SERIAL(CElement,CObject,VERSION_NUMBER)
IMPLEMENT_SERIAL(CLine,CElement,VERSION_NUMBER)

// CElement

CElement::CElement()
{
}

void CElement::Serialize(CArchive& ar)
{

CObject::Serialize(ar);//调用基本类函数
if (ar.IsStoring())
{
ar  << m_Color        
    << m_EnclosingRect   
    << m_Pen;   
}
else
{
ar  >> m_Color      
    >> m_EnclosingRect   
    >> m_Pen;    
}
}
CElement::~CElement()
{
}


// CElement 成员函数


CLine::CLine(CPoint Start,CPoint End,COLORREF aColor,int PenWidth)  //CLine类的构造函数
{
m_StartPoint=Start;        //设置直线起点,储存在由基类CElement继承而来的变量m_StartPoint中
m_EndPoint=End;            //设置直线终点
m_Color=aColor;            //设置直线颜色
m_Pen=PenWidth;                   //设置画笔宽度
//定义封闭矩形
m_EnclosingRect=CRect(Start,End); //设置封闭矩形的起点和终点
m_EnclosingRect.NormalizeRect();  //把封闭矩形规范化
}
void CLine::Serialize(CArchive& ar)
{
CElement::Serialize(ar);//调用基本类函数
if (ar.IsStoring())
{
ar  << m_StartPoint       //存储第一个点
    << m_EndPoint;         //最后一个点
  相关解决方案