I have functions of this type:
type uniRndtype()
{
return typeValue;
}
and now I'm trying to wrap them inside another template function like this:
template<typename T>
T(* uniRndType(void))()
{
if (is_same<T, bool>::value)
{
return uniRndBool;
} else if (is_same<T, char>::value)
{
return uniRndChar;
} else
...
}
and calling it like this:
uniRndType<int>();
But I'm getting an error: "error: return value type does not match the function type" because each return has a different type..
I there a way to make it work? Because from a runtime point of view I see no errors, only the compiler have problems.
static_castto cast the function to your return type. - BarmarTin order to instanciate the method. If you called it with a string,uniRndType<std::string>()then how would the compiler handle the fact you've got code that returns a boolean value? - Seanreturn (T(*)(void))uniRndType;fixed the problem. - Vladp