What are the consequences of ignoring: warning: unused parameter

前端 未结 8 761
闹比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:15

    In C++ you can have default arguments:

    int sum(int first, int second=0){   // should not give warning
        return first+first;
    }
    

    You can also have extra argument:

    int sum(int first, int second){     // should give warning
        first *= 2;
        return first;
    }
    

    If you have a parameter you're not using and it's not defaulted, you should get a warning because you're asking the program to pass extra values to the stack that are never referenced, and therefore is doing more work than it should.

    Maybe it means you forgot part of the function logic, too.

提交回复
热议问题