Avoid warning 'Unreferenced Formal Parameter'

前端 未结 7 2424
天命终不由人
天命终不由人 2020-12-04 17:54

I have a super class like this:

class Parent
{
public:
    virtual void Function(int param);
};

void Parent::Function(int param)
{
    std::cout << pa         


        
7条回答
  •  鱼传尺愫
    2020-12-04 18:19

    As @Charles Bailey mentioned, you can skip the parameter name.

    However, in certain scenarios, you need the parameter name, since in debug builds you are calling an ASSERT() on it, but on retail builds it's a nop. For those scenarios there's a handy macros (at least in VC++ :-)) UNREFERENCED_PARAMETER(), which is defined like this:

    #define UNREFERENCED_PARAMETER(x) x
    

    Note that the simple cast @R Samuel Klatchko posted also works, but I personally find it more readable if the code is explicit that this is an unreferenced parameter vs. simple unexplained cast like that.

提交回复
热议问题