Přemysl Šťastný Přemysl Šťastný - 1 year ago 85
C++ Question

Can I declare variable just from std::type_info?

Can I declare variable just from

? I would like to do something like this:

void some(type_info type)
type variable;

I would like to give as the parameter to function type of class and initialize it in it.

Answer Source

Your best bet is to use a template:

template <typename T>
void some()
    T variable;


As C++ is statically typed, it is impossible to determine vairable type in runtime, so all types should be known at compile time anyway.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download