Possible Duplicate:
casting unused return values to void
I read some source code, and in it many virtual functions in the interface classes are declared and default-implemented as such:
virtual bool FunctionName(TypeName* pointer)
{
(void)pointer;
return true;
}
May I ask what is the purpose of casting the pointer to void in the default implementation?
Multiple purposes depending on what you cast
T, and you return the result of some function call that could be different fromTin some situation. An explicit cast toTcould, in thevoidcase, prevent a compile time error:int f() { return 0; } void g() { return (void)f(); }(void)a, bwill never invoke an overloaded comma operator function).Note that the Standard guarantees that there will never be an
operator void()called if you cast a class object tovoid(some GCC versions ignore that rule, though).