Since C++ is a statically typed language, you cannot really do this in a simple way. You cannot determine types at runtime, these are fixed as soon your program has been compiled.
The closest thing you can get for your case IMHO, is using something like a boost::variant or boost::any.