Possible Duplicate:
casting unused return values to void

I just read some source code, as well as in it many virtual functions within the interface courses are declared and default-implemented as a result:

virtual bool FunctionName(TypeName* pointer)
{
   (void)pointer;
   return true;
}

May I request what's the reason for casting the pointer to void within the default implementation?

Multiple reasons based on that which you cast

  • Marking your intention towards the compiler that the expression that's entirely a no-op is supposed as written (for suppressing alerts, for instance)
  • Marking your intention to towards the compiler and programmer that caused by something is overlooked (the effect of a fuction call, for instance)
  • Inside a function template, if your return type is offered with a template parameter type T, and also you return caused by some function call that may be not the same as T in certain situation. An explicit cast to T could, within the void situation, prevent a compile time error:
    int f() { return 0; } void g() { return (void)f(); }
  • Suppressing the compiler to select a comma operator overload ((void)a, b won't ever invoke an overloaded comma operator function).

Observe that the conventional guarantees there should never be an operator void() known as should you cast a category resist void (some GCC versions ignore that rule, though).

Within this situation it is simply to prevent compiler's warning about unused parameter.