Why does C++ code missing a formal argument name in a function definition compile without warnings?

前端 未结 4 752
闹比i
闹比i 2020-11-29 01:44

While getting started with some VS2005-generated MFC code, I noticed it overrode a method with something like this:

void OnDraw(CDC* /*pDC*/)
{
    ...
    /         


        
4条回答
  •  星月不相逢
    2020-11-29 02:20

    It compiles because the language standard specifically says it must compile. There's no other answer. This is one of the bits that make C++ different from C. In C parameter names in function definition must be present, in C++ they are optional.

    I actually wonder why you ask your "why" question. Do you see anything unnatural, unusual or illogical in this behavior?

提交回复
热议问题