The following C++ code uses typeid to print out the runtime class of the parameter:
#include <iostream>
class Foo
{
};
class Bar: public Foo
{
};
template <class O> void printTypeName(O& object)
{
std::cout << typeid(object).name();
}
int main(void)
{
Bar x;
printTypeName(x);
}
Since Foo is not polymorphic, VS C++ doesn’t use the object to determine type information and raises
C4100 warning (“unreferenced formal parameter”).
Is there any way to get rid of the warning, while preserving the possibility to print out the object type with a simple method call? I would prefer not to have to disable the warning.
There’s an
UNREFERENCED_PARAMETERmacro you can use for that.====
Edited by the OP: one can also use
(void) object;and avoid using the macro (credits to David Rodriguez for his comment about it).