There are two basic problems.

First, you can't overload a function, even by templates like this, based only on the return type.

Second, by the time you can supply a string, you already MUST know the return type, obviating the necessity of the string specifying the return type.

What you can do is overload using a reference...

template <typename T> funcion( T & i ) {... }


Consider the calling code. If you're going to instantiate the function on behalf of a float, your call, if it were even possible, would have to be something like:


float v = convert<float>( floatstring );

Why would you want to provide a string stating the return type? It's redundant information. You could not determine the type of the return value based on the template - that is v isn't going to modulate it's type in this context, or any context in which you make a call (though the variant type is theoretically 'any' type, it is, itself, a type).

Since you can't overload based on return type, you would:

float v;

convert( v );

However, the context of this call is what's important. Is your reason for wanting a string based on some user input selection?

I'd need more to go on before I drift off into a tangent outside you're interest. What we need to know in order to be of help is why you're doing this and what the context is, how are you deciding what type to convert to?