Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualJuliean

Posted 21 June 2013 - 02:03 PM

Wait.. since when do you need a different sqrt-function for different data types? Did I miss somehing, or is this just an example? You could however delegate this problem with using a global function that is overloaded for the different data types:

void mySqrt(int x)
{
return sqrtl(x);
}

void mySqrt(float x)
{
return sqrt(x);
}

void mySqrt(double x)
{
return sqrt(x);
}

Now call mySqrt in length() instead of sqrt, and only provide this one implementation, the correct function overload will be choosen for you. Downside is that you now need an explicit implementation for every data type, unless this works with a forth templated function too (you'd have to try).

 

EDIT: Being ninja'd by the OP... now that just sucks :P


#1Juliean

Posted 21 June 2013 - 02:03 PM

Wait.. since when do you need a different sqrt-function for different data types? Did I miss somehing, or is this just an example? You could however delegate this problem with using a global function that is overloaded for the different data types:

void mySqrt(int x)
{
return sqrtl(x);
}

void mySqrt(float x)
{
return sqrt(x);
}

void mySqrt(double x)
{
return sqrt(x);
}

Now call mySqrt in length() instead of sqrt, and only provide this one implementation, the correct function overload will be choosen for you. Downside is that you now need an explicit implementation for every data type, unless this works with a forth templated function too (you'd have to try).


PARTNERS