Why comment on parameter names rather than leaving them as they are

Sometimes I see this code:

LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)

Why comment on parameter names rather than leaving them as they are?

+5
source share
6 answers

One of the reasons I see this is because you clearly want to tell other programmers not to use parameters, but leave them in the comments to describe their intentions. I know this doesn't make sense now, but read on.

I will use another example:

class A
{
public:
   virtual void foo(int someProperty);
};

class B : public A
{
public:
   virtual void foo(int /*someProperty*/);
};

, , , B::foo() , A::foo() 0. , , B::foo() . . , , " someProperty".

B::foo(int/*someProperty*/)
{
    //do some stuff
    A::foo(0);
}

( ). - , A::foo() - "someProperty" A.

, .

+6

, / , " ", , , .

, , , , . , , .

, , , , .

+10

,

, , .

, .

.

+3

onPaint(), , "unreferenced formal parameter" ( , -W4 Microsoft).

+2

(OnPaint ) , , .

0

Some compilers did not give a “warning about unused arguments” when you comment on an argument or do not provide it in the first place. But, of course, you need to leave the type in order to have the correct signature.

0
source

All Articles