Specifying function parameter type, but not variable
c++, c++11, function, parameters
Solution
This is commonly done to suppress compiler warnings about unused variables. When you do not create a variable name, the compiler will not warn you that the variable is not being used in the function.
Like you stated, its usually that parameters are not being used for the particular implementation:
class an_iface
{
public:
an_iface();
virtual int doSomething(int valNeeded)=0;
}
#define NOT_SUPPORTED -1
class something : public an_iface
{
public:
something();
int doSomething (int) { return NOT_SUPPORTED; }
}
class somethingMore : public an_iface
{
public:
somethingMore();
int doSomething(int stuff) { return stuff * 10; }
}
Problem
I have seen example code like this before ``` class C { C(); ~C(); foo(T1, T2); } C::foo(T1, T2) { //not using T1/T2 } ``` versus conventional code like this ``` class D { D(); ~D(); bar(T1 t1, T2 t2); } D::bar(T1 t1, T2 t2) { //using t1 and t2 } ``` And I am wondering what is the purpose of not defining your type variables for usability? Do most people do this just to hint that those parameters of the api are not currently in use, but to ensure backward compatibility in the future? Is it possibly for RTTI, or referencing static variables (although the various samples I've seen were not using it for this purpose, they werent even templated functions, the variables were simply unused). I've tried searching for this feature but I am not even sure what it is called or what to search. Basically, what are the reasons/benefits/downsides for using this approach?