需要帮助C++代码解析/*= NULL*/

Nan*_* HE 0 c++ comments

你能告诉我/*=NULL*/下面的意思吗?

CMyCla::CMyCla(CWnd* pParent /*=NULL*/)
    : CDialog(CCycleTimes::IDD, pParent)
{
    // Some code here
}
Run Code Online (Sandbox Code Playgroud)

顺便说一句,我复制了同一条线.

成功评论为下面的syte

// CMyCla::CMyCla(CWnd* pParent /*=NULL*/)
//  : CDialog(CCycleTimes::IDD, pParent)
Run Code Online (Sandbox Code Playgroud)

否则,评论失败为下面的样式.

/*
    CMyCla::CMyCla(CWnd* pParent /*=NULL*/)
        : CDialog(CCycleTimes::IDD, pParent)
*/
Run Code Online (Sandbox Code Playgroud)

为什么评论操作失败了?

sha*_*oth 10

最有可能在类声明中指定该参数的默认值:

class CMyCla {
public:
    CMyCla(CWnd* pParent =NULL);
};
Run Code Online (Sandbox Code Playgroud)

现在在CMyCla :: CMyCla()的实现中重新定义参数的默认值是不允许的,但是作者或许想提醒一下有默认值,所以他把它评论出来了.

执行以下操作时:

/* 
    CMyCla::CMyCla(CWnd* pParent /*=NULL*/) 
        : CDialog(CCycleTimes::IDD, pParent) 
*/ 
Run Code Online (Sandbox Code Playgroud)

第一个结束注释(*/)结束注释部分,因此它之后的所有内容现在都取消注释:

/*<CommentStart>
    CMyCla::CMyCla(CWnd* pParent /*=NULL*/<CommentEnd>)<-this is not commented
        : CDialog(CCycleTimes::IDD, pParent) <-neither is this
*/<-this closing comment can produce a compiler error
Run Code Online (Sandbox Code Playgroud)


Ian*_*oss 5

评论在您的上一个案例中不起作用,因为/**/样式注释不会嵌套.你不能把一个/**/评论放在另一个评论中.