What are the consequences of ignoring: warning: unused parameter

前端 未结 8 841
闹比i
闹比i 2020-12-29 23:48

I am working on a C++ project and I noticed that we have a number of warnings about unused parameters.

What effect could it have if these warnings are ignored?

8条回答
  •  情话喂你
    2020-12-30 00:06

    That depends of if you intended to use the paramater. E.g.

    const int Size = 12; // intended for use in some other function
    
    char* MakeBuffer(int size)
    {
       return new char[Size];
    }
    

    In this code 'size' is unused, and instead the constant 'Size' is being used. So the warning will highlight problems of this type for you.

    However, if you never indented to use the parameter then it should just be removed from the method signature. Unless you need to match a signature for a virtual method, or function pointer, if that's the case then you don't have the option to remove it.

提交回复
热议问题