2013-02-10 55 views
0

我試着製作MyWindowSplitter類,並且我在MySplitter類中將另一個從CView類派生出來的新類作爲運行時類。但是,當我試圖編譯我在GetDocument功能得到了在MyProjectView.h這些錯誤:如何修復丟失的';'在我的程序中出現'*'錯誤之前?

Error 1 
error C2143: syntax error : missing ';' before '*' 

Error 2 
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 

在哪裏的問題,我怎樣才能解決這些問題?

//MySplitter.cpp 
#include "StdAfx.h" 
#include "MySplitter.h" 
#include "SplitDemoSixView.h" 
#include "TestView.h" 

#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 

CMySplitter::CMySplitter(void) 
{ 
} 

CMySplitter::~CMySplitter(void) 
{ 
} 

void CMySplitter::ChangeViewClass(CRuntimeClass* pNewView) 
{ 
m_pDynamicViewClass = pNewView; 
} 

void CMySplitter::DeleteView(int row, int col) 
{ 
CView* pView = (CView*)GetDlgItem(IdFromRowCol(row, col)); 

if(pView->IsKindOf(RUNTIME_CLASS(CSplitDemoSixView))) 
{ 
    ChangeViewClass(RUNTIME_CLASS(CSplitDemoSixView)); 
} 
else 
{ 
    if(pView->IsKindOf(RUNTIME_CLASS(CTestView))) 
    { 
     ChangeViewClass(RUNTIME_CLASS(CTestView)); 
    } 
} 

CSplitterWnd::DeleteView(row, col); 
} 

//TestView.cpp drived from CView 

#include "stdafx.h" 
#include "SplitDemoSix.h" 
#include "TestView.h" 
#include "SplitDemoSixDoc.h" 
#include "SplitDemoSixView.h" 


// CTestView 

IMPLEMENT_DYNCREATE(CTestView, CView) 

CTestView::CTestView() 
{ 

} 

CTestView::~CTestView() 
{ 
} 

BEGIN_MESSAGE_MAP(CTestView, CView) 
END_MESSAGE_MAP() 


// CTestView drawing 

void CTestView::OnDraw(CDC* pDC) 
{ 
CDocument* pDoc = GetDocument(); 
// TODO: add draw code here 
} 


// CTestView diagnostics 

#ifdef _DEBUG 
void CTestView::AssertValid() const 
{ 
CView::AssertValid(); 
} 

#ifndef _WIN32_WCE 
void CTestView::Dump(CDumpContext& dc) const 
{ 
CView::Dump(dc); 
} 
#endif 
#endif //_DEBUG 


// CTestView message handlers 

,問題就在這裏:

//MyProjectView.h 

#pragma once 

#include "resource.h" 
#include "MySplitter.h" 


class CSplitDemoSixView : public CFormView 
{ 
protected: // create from serialization only 
CSplitDemoSixView(); 
DECLARE_DYNCREATE(CSplitDemoSixView) 

public: 
enum{ IDD = IDD_SPLITDEMOSIX_FORM }; 

// Attributes 
public: 
    //ERROR PERFORMS IN THIS FUNCTION: 
CSplitDemoSixDoc* GetDocument(); 

// Operations 
public: 

// Overrides 
public: 
virtual BOOL PreCreateWindow(CREATESTRUCT& cs); 
protected: 
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support 
virtual void OnInitialUpdate(); 
... 
+1

頭定義'CSplitDemoSixDoc'應包括或類型必須是前向聲明的。 – 2013-02-10 14:33:35

+1

你的宏擴展中是否有分號? – 0x499602D2 2013-02-10 14:33:57

+0

我認爲這個答案解決了它 - http://stackoverflow.com/questions/1542623/syntax-error-missing-before?rq=1 – 0x499602D2 2013-02-10 14:38:33

回答

1

您需要爲您的CDocument派生類前向聲明​​:

// Attributes 
public: 
    //ERROR PERFORMS IN THIS FUNCTION: 
class CSplitDemoSixDoc; 
CSplitDemoSixDoc* GetDocument(); 
+0

謝謝。它修復了。 – goodstarter 2013-02-10 16:14:21

相關問題