一个数据成员的初始化问题
在David J. Kruglinski写的那本programming vc++书中有这样一个例子:
EX04AVIEW.H
// ex04aView.h : interface of the CEx04aView class
//
///////////////////////////////////////////////////////////////////////
#if !defined(AFX_EX04AVIEW_H__B188BE41_6377_11D0_8FD4_00C04FC2A0C2
__INCLUDED_)
#define AFX_EX04AVIEW_H__B188BE41_6377_11D0_8FD4_00C04FC2A0C2
__INCLUDED_
#if _MFC_VER > 1000
#pragma once
#endif // _MFC_VER > 1000
class CEx04aView : public CView
{
protected: // create from serialization only
CEx04aView();
DECLARE_DYNCREATE(CEx04aView)
// Attributes
public:
CEx04aDoc* GetDocument();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEx04aView)
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);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CEx04aView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CEx04aView)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
int m_nColor;
CRect m_rectEllipse;
};
#ifndef _DEBUG // debug version in ex04aView.cpp
inline CEx04aDoc* CEx04aView::GetDocument()
{ return (CEx04aDoc*)m_pDocument; }
#endif
///////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations
// immediately before the previous line.
#endif // !defined(AFX_EX04AVIEW_H__B188BE41_6377_11D0_8FD4_00C04FC2A0C2__INCLUDED_)
EX04AVIEW.CPP
// ex04aView.cpp : implementation of the CEx04aView class
//
#include "stdafx.h"
#include "ex04a.h"
#include "ex04aDoc.h"
#include "ex04aView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE
__;
#endif
///////////////////////////////////////////////////////////////////////
// CEx04aView
IMPLEMENT_DYNCREATE(CEx04aView, CView)
BEGIN_MESSAGE_MAP(CEx04aView, CView)
//{{AFX_MSG_MAP(CEx04aView)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////
// CEx04aView construction/destruction
CEx04aView::CEx04aView() : m_rectEllipse(0, 0, 200, 200)
{
m_nColor = GRAY_BRUSH;
}
CEx04aView::~CEx04aView()
{
}
BOOL CEx04aView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
///////////////////////////////////////////////////////////////////////
// CEx04aView drawing
void CEx04aView::OnDraw(CDC* pDC)
{
pDC->SelectStockObject(m_nColor);
pDC->Ellipse(m_rectEllipse);
}
///////////////////////////////////////////////////////////////////////
// CEx04aView printing
BOOL CEx04aView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CEx04aView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CEx04aView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
///////////////////////////////////////////////////////////////////////
// CEx04aView diagnostics
#ifdef _DEBUG
void CEx04aView::AssertValid() const
{
CView::AssertValid();
}
void CEx04aView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CEx04aDoc* CEx04aView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx04aDoc)));
return (CEx04aDoc*)m_pDocument;
}
#endif //_DEBUG
///////////////////////////////////////////////////////////////////////
// CEx04aView message handlers
void CEx04aView::OnLButtonDown(UINT nFlags, CPoint point)
{
if (m_rectEllipse.PtInRect(point)) {
if (m_nColor == GRAY_BRUSH) {
m_nColor = WHITE_BRUSH;
}
else {
m_nColor = GRAY_BRUSH;
}
InvalidateRect(m_rectEllipse);
}
}
我搞不明白在
CEx04aView::CEx04aView() : m_rectEllipse(0, 0, 200, 200)
{
m_nColor = GRAY_BRUSH;
}
中m_rectEllipse(0, 0, 200, 200)为什么要写在这个地方?写在括号里面不可以么?