Compiler error output,
1>MainFrm.cpp
1>z:\. . . . viewswitchview.h(19) : error C2143: syntax error : missing ';' before '*'
1>z:\. . . . viewswitchview.h(19) : error C4430: missing type specifier - int assumed.
1>z:\. . . . viewswitchview.h(19) : error C4430: missing type specifier - int assumed.
1>z:\. . . . viewswitchview.h(19) : warning C4183: 'GetDocument': missing return type;
assumed to be a member function returning 'int'
Comments in code specify where error is and what makes it happen, which is the including one specific include file.
Code:
//=========Here is the MainFrm.cpp file paste=============
// KEEP IN MIND, These errors ONLY occur when I add the
// #include "ViewSwitchView.h" as shown below.
// MainFrm.cpp : implementation of the CMainFrame class
#include "stdafx.h"
#include "ViewSwitch.h"
#include "MainFrm.h"
#ifndef _ViewSwitchView_H_ // Added by me ******************
#include "ViewSwitchView.h" // IF I COMMENT THIS LINE ONLY, PROJECT COMPILES WITH NO ERRORS OR WARNINGS.
#endif //_ViewSwitchView_H_ // SEE THE INCLUDE FILE BELOW AFTER THIS MainFrm.cpp, for error line.
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()
static UINT indicators[] =
{ ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{ if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{ TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{ TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{ if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{ CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{ CFrameWnd::Dump(dc);
}
#endif //_DEBUG
// CMainFrame message handlers
// There are none at this time.
//=============End of MainFrm.cpp file===========================
//==============include file paste===============================
// ViewSwitchView.h : interface of the CViewSwitchView class
//
#ifndef _ViewSwitchView_H_
#define _ViewSwitchView_H_ // Note this does not prevent error
#endif //_ViewSwitchView_H_
#pragma once
class CViewSwitchView : public CView
{protected: // create from serialization only
CViewSwitchView();
DECLARE_DYNCREATE(CViewSwitchView)
// Attributes
public:
CViewSwitchDoc* GetDocument() const; //<-- this line (19) flags the error if I include this
// file in MainFrm.cpp, even with the ifndef's above
// Operations
public:
// Overrides
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);
// Implementation
public:
virtual ~CViewSwitchView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
DECLARE_MESSAGE_MAP()
public:
};
#ifndef _DEBUG // debug version in ViewSwitchView.cpp
inline CViewSwitchDoc* CViewSwitchView::GetDocument() const
{ return reinterpret_cast<CViewSwitchDoc*>(m_pDocument); }
#endif
//-----------end of include file---------