C++ is a statically typed language, which implies that types pretty much do not exist in the runtime. Function return type is completely defined by parameter types (const char*
) and cannot depend on parameter values ("int"
).
Computational flow can be influenced by types, e.g. via overload - but not vice versa. As a result, you cannot "compute" a type by calling some function.
Instead you can use templates/decltype
/auto
to produce complex and context-dependent types in compile time, or use polymorphic types.
Polymorphic types do indeed have runtime-defined behavior: you can make your some-function
return an abstract factory, and then use that factory to produce your objects - their concrete type would be unknown at compile time. Of course, you would still need to instantiate the vector
with some static type - usually a pointer to the generic class (AbstractType*
).
The fact that you mention int
, char
and std::string
hints that you probably don't want the whole polymorphic hierarchy and can manage with static types.
Here are some templates to determine the result type of calling a function. Notice that the function is not even called - again, the return type only depends on parameter types, not some computation.