I was practicing to be able to make a recursive exponent, and it works but not with doubles
and floats
, I do debugging and I get warnings in the implementation of C ++. It's a very long follow-up but in the end I get the next output. -1.#IND
and if I put the return ternario comes out:
error LNK2019: unresolved external symbol "double __cdecl expo<double>(double,double)" (??$expo@N@@YANNN@Z) referenced in function _main
error LNK2019: unresolved external symbol "float __cdecl expo<float>(float,float)" (??$expo@M@@YAMMM@Z) referenced in function _main
This is my code:
#include <iostream>
template <typename TIPO>
TIPO expo (TIPO base, TIPO veces, TIPO cont = 1)
{
cont *= base;
if (veces < 0) return cont;
expo(base, 1 - veces, cont);
//lo mismo como operador ternario
//return (veces > 0) ? expo(base, --veces, cont * base) : cont;
}
int main()
{
float r = expo<float>(4.0,2.0);
std::cout << r << std::endl;
return 0;
}
Could someone tell me what my code is failing? Thanks for your time.