Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ virtual function with arguments getting warnings when unused

virtual void myFunc(int& a, int& b) {}

I get warnings about unused variables but I do not want to do anything with them in the base class. I want the derived classes to implement them if they want, and to do nothing if they do not implement them. What can I do to stop the warnings other than putting a flag on the compiler ?

like image 715
gda2004 Avatar asked Feb 12 '14 14:02

gda2004


2 Answers

Simply don't give them a name:

virtual void myFunc( int&, int& );
like image 145
jrok Avatar answered Sep 20 '22 16:09

jrok


Since you don't want to use them you can emit the parameter names.

However, instead of removing them completely it's sometimes more useful to comment them out like this:

virtual void myFunc(int& /* a */ , int& /* b */ ) 
{
}

This way you can still see what the intent of the parameter was by looking at the commented out name. This is particularly useful if you put the implementation in the header as it will be the only place which mentions the parameter names.

like image 20
Sean Avatar answered Sep 22 '22 16:09

Sean