VC头文件的包含顺序不同是不是对程序的影响也不同?
我发现一个奇怪的问题?问题描述如下:
CDMAView.h 文件内容:
// CDMAView.h : interface of the CCDMAView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_CDMAVIEW_H__45BF3A2B_F76F_4AC0_828A_595445F66B69__INCLUDED_)
#define AFX_CDMAVIEW_H__45BF3A2B_F76F_4AC0_828A_595445F66B69__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
//#include "CDMADoc.h"
//class CCDMADoc;
class CCDMAView : public CFormView
{
protected: // create from serialization only
CCDMAView();
DECLARE_DYNCREATE(CCDMAView)public:
//{{AFX_DATA(CCDMAView)
enum{ IDD = IDD_CDMA_FORM };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Attributes
public:
CCDMADoc * GetDocument();
// Operations
public: // Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCDMAView)
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
virtual void OnInitialUpdate(); // called first time after construct
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CCDMAView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endifprotected:// Generated message map functions
protected:
//{{AFX_MSG(CCDMAView)
// NOTE - the ClassWizard will add and remove member functions here.
//    DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};#ifndef _DEBUG  // debug version in CDMAView.cpp
inline CCDMADoc* CCDMAView::GetDocument()
   { return (CCDMADoc*)m_pDocument; }
#endif///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_CDMAVIEW_H__45BF3A2B_F76F_4AC0_828A_595445F66B69__INCLUDED_)
CDMAView.cpp 文件内容:
// CDMAView.cpp : implementation of the CCDMAView class
//#include "stdafx.h"
#include "CDMA.h"
#include "CDMADoc.h"
#include "CDMAView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CCDMAViewIMPLEMENT_DYNCREATE(CCDMAView, CFormView)BEGIN_MESSAGE_MAP(CCDMAView, CFormView)
//{{AFX_MSG_MAP(CCDMAView)
// 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
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CCDMAView construction/destructionCCDMAView::CCDMAView()
: CFormView(CCDMAView::IDD)
{
//{{AFX_DATA_INIT(CCDMAView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here}CCDMAView::~CCDMAView()
{
}void CCDMAView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCDMAView)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}BOOL CCDMAView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
//  the CREATESTRUCT cs return CFormView::PreCreateWindow(cs);
}void CCDMAView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();}/////////////////////////////////////////////////////////////////////////////
// CCDMAView printingBOOL CCDMAView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}void CCDMAView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}void CCDMAView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}void CCDMAView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}/////////////////////////////////////////////////////////////////////////////
// CCDMAView diagnostics#ifdef _DEBUG
void CCDMAView::AssertValid() const
{
CFormView::AssertValid();
}void CCDMAView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}CCDMADoc* CCDMAView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCDMADoc)));
return (CCDMADoc*)m_pDocument;
}
#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
// CCDMAView message handlers编译有如下错误:d:\my porjects\vc\cdma\cdmaview.h(28) : error C2143: syntax error : missing ';' before '*'
d:\my porjects\vc\cdma\cdmaview.h(28) : error C2501: 'CCDMADoc' : missing storage-class or type specifiers
d:\my porjects\vc\cdma\cdmaview.h(28) : error C2501: 'GetDocument' : missing storage-class or type specifiers更改 CDMAView.cpp 文件的头文件包含顺序
// CDMAView.cpp : implementation of the CCDMAView class
//#include "stdafx.h"
#include "CDMA.h"
#include "CDMAView.h" //这两个文件的顺序调换。
#include "CDMADoc.h"  //
有如下错误:
d:\my porjects\vc\cdma\cdmaview.h(28) : error C2143: syntax error : missing ';' before '*'
d:\my porjects\vc\cdma\cdmaview.h(28) : error C2501: 'CCDMADoc' : missing storage-class or type specifiers
d:\my porjects\vc\cdma\cdmaview.h(28) : error C2501: 'GetDocument' : missing storage-class or type specifiers
D:\MY PORJECTS\VC\CDMA\CDMAView.cpp(112) : error C2556: 'class CCDMADoc *__thiscall CCDMAView::GetDocument(void)' : overloaded function differs only by return type from 'int *__thiscall CCDMAView::GetDocument(void)'
        d:\my porjects\vc\cdma\cdmaview.h(28) : see declaration of 'GetDocument'
D:\MY PORJECTS\VC\CDMA\CDMAView.cpp(112) : error C2371: 'GetDocument' : redefinition; different basic types
        d:\my porjects\vc\cdma\cdmaview.h(28) : see declaration of 'GetDocument'
MainFrm.cpp
d:\my porjects\vc\cdma\cdmaview.h(28) : error C2143: syntax error : missing ';' before '*'
d:\my porjects\vc\cdma\cdmaview.h(28) : error C2501: 'CCDMADoc' : missing storage-class or type specifiers
d:\my porjects\vc\cdma\cdmaview.h(28) : error C2501: 'GetDocument' : missing storage-class or type specifiers