There are at least two approaches.
First, create an instance using an if/switch statement based on user input, then store this instance in a pointer that does not know what the particular type is. It can be a pointer to an abstract base class, or a type erased pointer to a generated wrapper (like what std::function does), or a pointer to the equivalent of void and a variable to say what type it is to be used later. Variations of this are doable in C Java and many other languages.
A second way is to switch on user input, generate the object, then proceed to run code that knows the object type generated by template. You could do this with copy paste or macros or code generation in C and other C derived languages, but this kind of in language code generation is a newish technique in that lineage. Most similar generic code in other C derived languages is actually obscured type erasure.
newobject?