在看<<vc技术内幕》第4版是有个问题??
//ex04aView.h
private:
int m_nColor;
CRect m_rectEllipse;.........................
CEx04aView::CEx04aView() : m_rectEllipse(0, 0, 200, 200)
{
m_nColor = GRAY_BRUSH;
}
向m_rectEllipse这样的初始化,那么为什么要写在上面
这样可以吗??
CEx04aView::CEx04aView() 
{
        m_rectEllipse(0, 0, 200, 200)
m_nColor = GRAY_BRUSH;
}

解决方案 »

  1.   

    CEx04aView::CEx04aView() : m_rectEllipse(0, 0, 200, 200),m_nColor = GRAY_BRUSH
    {

    }
    应该也是正确的写法吧
      

  2.   

    CEx04aView::CEx04aView() : m_rectEllipse(0, 0, 200, 200),m_nColor = GRAY_BRUSH
    {

    }
    不是正确的写法CEx04aView::CEx04aView() : m_rectEllipse(0, 0, 200, 200),m_nColor(GRAY_BRUSH)
    {

    }
    是正确的写法        m_rectEllipse(0, 0, 200, 200)这样写在函数体内也是不对的
      

  3.   

    CEx04aView::CEx04aView() : m_rectEllipse(0, 0, 200, 200), m_nColor(GRAY_BRUSH){
    }
    或者
    CEx04aView::CEx04aView()
    {
    m_rectEllipse = CRect(0, 0, 200, 200);
    m_nColor = GRAY_BRUSH;
    }
      

  4.   

    CEx04aView::CEx04aView() : m_rectEllipse(0, 0, 200, 200)
    {
    m_nColor = GRAY_BRUSH;
    }
    这样写是因为m_rectEllipse是一个类对象,如果放在函数体里,要先调用默认构造函数进行构造,再来一次赋值。浪费时间