我尝试制作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();
...
最佳答案
您需要对CDocument派生的类进行前向声明:
// Attributes
public:
//ERROR PERFORMS IN THIS FUNCTION:
class CSplitDemoSixDoc;
CSplitDemoSixDoc* GetDocument();
关于c++ - 我该如何解决缺少的';'在程序中出现“*”错误之前?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14798774/