What is going on at the top of this function

2019-08-19 03:50发布

I'm currently looking at a function example that I can't seem to figure out using MFC in Visual C++. The function is as follows

CMFC_OSG_MDIView::CMFC_OSG_MDIView() :mOSG(0L)
{
}

I understand everything here except the mOSG(0L) snippet. mOSG was declared in the MFC_OSG _MDIView class as follows:

cOSG* mOSG;

3条回答
淡お忘
2楼-- · 2019-08-19 04:19

0L specifies a long integer with value zero. So this initializes the class member mOSG with 0.

查看更多
Juvenile、少年°
3楼-- · 2019-08-19 04:21

That's an initializer - mOSG is initialized with 0L. When the control enters the constructor body mOSG is already initialized.

See this question for discussion of why use initializers instead of assignment inside of the constructor.

查看更多
劫难
4楼-- · 2019-08-19 04:35
CMFC_OSG_MDIView::CMFC_OSG_MDIView() :mOSG(0L)
{
}

The above is a constructor, for a class called CMFC_OSG_MDIView. :mOSG(0L) is called initializer list, which is executed when an object is created. The init-list gets called before the body of the constructor, and it is the correct place to initialize the member variables.

查看更多
登录 后发表回答