Přemysl Šťastný Přemysl Šťastný - 2 months ago 10
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.


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.