我正在VS2010中创建一个简单的MFC文本编辑器,以便学习C ++,而且我遇到了一些绊脚石....
具体来说,我在构建日志中收到以下错误:
1> Generating Code...
1>Link:
1> Creating library C:\Users\Alvin\Documents\Visual Studio 2010\Projects\Emergence\Debug\EmergenceHandlers.lib and object C:\Users\Alvin\Documents\Visual Studio 2010\Projects\Emergence\Debug\EmergenceHandlers.exp
1>EmergenceDoc.obj : error LNK2019: unresolved external symbol "public: __thiscall CEmergenceCntrItem::CEmergenceCntrItem(struct _reobject *,class CEmergenceDoc *)" (??0CEmergenceCntrItem@@QAE@PAU_reobject@@PAVCEmergenceDoc@@@Z) referenced in function "public: virtual class CRichEditCntrItem * __thiscall CEmergenceDoc::CreateClientItem(struct _reobject *)const " (?CreateClientItem@CEmergenceDoc@@UBEPAVCRichEditCntrItem@@PAU_reobject@@@Z)
1>C:\Users\Alvin\Documents\Visual Studio 2010\Projects\Emergence\Debug\EmergenceHandlers.dll : fatal error LNK1120: 1 unresolved externals
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:06.52
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========
以下是CEmergenceCntrItem出现的所有文件....
cntritem.h:
#include "afxrich.h"
#include "Resource.h"
class CEmergenceDoc;
class CEmergenceView;
class CEmergenceCntrItem : public CRichEditCntrItem
{
DECLARE_SERIAL(CEmergenceCntrItem)
public:
CEmergenceCntrItem(REOBJECT* preo = NULL, CEmergenceDoc* pContainer = NULL);
public:
CEmergenceDoc* GetDocument()
{ return (CEmergenceDoc*)COleClientItem::GetDocument(); }
CEmergenceView* GetActiveView()
{ return (CEmergenceView*)COleClientItem::GetActiveView(); }
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CWordPadCntrItem)
public:
protected:
//}}AFX_VIRTUAL
// Implementation
public:
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
};
EmergenceView.cpp:
#include "afxrich.h"
#pragma once
class CEmergenceCntrItem;
class CEmergenceView : public CRichEditView
{
protected: // create from serialization only
CEmergenceView();
DECLARE_DYNCREATE(CEmergenceView)
public:
CEmergenceDoc* GetDocument() const;
public:
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
public:
virtual ~CEmergenceView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
protected:
afx_msg void OnFilePrintPreview();
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnMutateGroup();
};
#ifndef _DEBUG // debug version in EmergenceView.cpp
inline CEmergenceDoc* CEmergenceView::GetDocument() const
{ return reinterpret_cast<CEmergenceDoc*>(m_pDocument); }
#endif
EmergenceDoc.cpp
#include "stdafx.h"
#include "Emergence.h"
#include "EmergenceDoc.h"
#include "CntrItem.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CEmergenceDoc, CRichEditDoc)
BEGIN_MESSAGE_MAP(CEmergenceDoc, CRichEditDoc)
//{{AFX_MSG_MAP(CMyWordDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Enable default OLE container implementation
ON_UPDATE_COMMAND_UI(ID_OLE_EDIT_LINKS,
CRichEditDoc::OnUpdateEditLinksMenu)
ON_COMMAND(ID_OLE_EDIT_LINKS, CRichEditDoc::OnEditLinks)
ON_UPDATE_COMMAND_UI_RANGE(ID_OLE_VERB_FIRST,
ID_OLE_VERB_LAST, CRichEditDoc::OnUpdateObjectVerbMenu)
END_MESSAGE_MAP()
CEmergenceDoc::CEmergenceDoc()
{
}
CEmergenceDoc::~CEmergenceDoc()
{
}
BOOL CEmergenceDoc::OnNewDocument()
{
if (!CRichEditDoc::OnNewDocument())
return FALSE;
return TRUE;
}
CRichEditCntrItem* CEmergenceDoc::CreateClientItem(REOBJECT* preo) const
{
return new CEmergenceCntrItem(preo, (CEmergenceDoc*) this);
}
void CEmergenceDoc::Serialize(CArchive& ar)
{
CRichEditDoc::Serialize(ar);
}
CntrItem.cpp
#include "stdafx.h"
#include "Emergence.h"
#include "EmergenceDoc.h"
#include "EmergenceView.h"
#include "cntritem.h"
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_SERIAL(CEmergenceCntrItem, CRichEditCntrItem, 0)
CEmergenceCntrItem::CEmergenceCntrItem(REOBJECT *preo, CEmergenceDoc* pContainer)
: CRichEditCntrItem(preo, pContainer)
{
}
#ifdef _DEBUG
void CEmergenceCntrItem::AssertValid() const
{
CRichEditCntrItem::AssertValid();
}
void CEmergenceCntrItem::Dump(CDumpContext& dc) const
{
CRichEditCntrItem::Dump(dc);
}
#endif
非常感谢任何帮助。
答案 0 :(得分:0)
只需将cntritem.cpp和cntritem.h复制到资源文件夹即可!