Avoid warning 'Unreferenced Formal Parameter'

前端 未结 7 2431
天命终不由人
天命终不由人 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:08

    Pragma works nicely too since it's clear you are using VS. This warning has a very high noise to benefit ratio, given that unreferenced parameters are very common in callback interfaces and derived methods. Even teams within Microsoft Windows who use W4 have become tired of its pointlessness (would be more suitable for /Wall) and simply added to their project:

    #pragma warning(disable: 4100)
    

    If you want to alleviate the warning for just a block of code, surround it with:

    #pragma warning(push)
    #pragma warning(disable: 4100)
    void SomeCallbackOrOverride(int x, float y) { }
    #pragma warning(pop)
    

    The practice of leaving out the parameter name has the downside in the debugger that you can't easily inspect by name nor add it to the watch (becomes confused if you have more than one unreferenced parameter), and while a particular implementation of a method may not use the parameter, knowing its value can help you figure out which stage of a process you are in, especially when you do not have the whole call stack above you.

提交回复
热议问题