Is there any generic variable type?

I’d like to pass two pieces of data to a function. One will be either a float, int, or string. And the other will be an integer telling you what type of data the first value is, in order to cast it.

is there any type of generic variable type i can use as an intermediary before casting?

Passing generic objects and types to a function and casting inside looks like something you should rework in your design, that’s usually a sign that it should be done in a different way.

Anyway, there are safer methods to have functions that receive different types of parameters:

  1. Method overloading, define methods with the same name for each type you want, each one receiving only one variable of a concrete type and the compiler will know what method to call. If methods are similar enough (they should, since you’re making a unique function to handle all of them) you can call any of the other to avoid repeating code 3 times.

  2. Use generic functions, define only one function this way:

    void function<T>(T param) {
        /* do stuff */
    }
    

and then call the function this way:

function<someClass>(myVariableOfThatClass);

You could use object