我怎样才能修复缺失';'在我的程序中出现'*'错误之前?

时间:2013-02-10 14:31:50

标签: c++ visual-c++

我尝试创建MyWindowSplitter类,并将另一个从CView类派生的新类作为MySplitter类中的运行时类。但是当我尝试编译时,我在MyProjectView.h函数中的GetDocument中收到了这些错误:

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 个答案:

答案 0 :(得分:1)

您需要CDocument派生类的前向声明:

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