### Template problem

Okay so what exactly am I doing wrong here?
 ``1234567891011121314151617181920212223242526272829`` ``````//inside class template const double power(double, T); //outside class template<> const double math::power(double a, signed int b) { bool return2 = false; double value = a; if(b < 0){ b = absolute(b); return2 = true; } for(unsigned int i = 1; i const double math::power(double a, double b) //error with this line { b *= 10000; bool return2 = false; double value = a; if(b < 0){ b = absolute(b); return2 = true; } for(unsigned int i = 1; i

I am getting an error with my second templated function
error: specialization of 'const double math::power(double, T) [with T = double]' after instantiation

Any help or suggestions would be greatly appreciated
-Giblit
ps: I haven't finished the second template function 100% so that it will take in fractions instead of doubles but that doesn't have an effect on my problem because I tried it with an output message and still got the error.
Last edited on
First, you don't actually need templates for this. This is standard function overloading:
 ``12345678`` ``````const double math::power(double a, signed int b) { //... } const double math::power(double a, double b) { //... }``````

However, regarding your errors, I am able to compile this fine:

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243`` ``````class math { public: template const double power(double, T); template T absolute(T in) { return in < T(0) ? T(-1)*in : in; } template T inverse(T in) { return T(1) / in; }; }; template<> const double math::power(double a, signed int b) { bool return2 = false; double value = a; if(b < 0){ b = absolute(b); return2 = true; } for(unsigned int i = 1; i const double math::power(double a, double b) //error with this line { b *= 10000; bool return2 = false; double value = a; if(b < 0){ b = absolute(b); return2 = true; } for(unsigned int i = 1; i

still new to c++ I had no idea you could overload functions like that thanks =] I was thinking you had to use templates to overload the functions. And maybe its my compiler though I think its mingw via qt because it did not compile for me I wish i read functions(2) lol http://www.cplusplus.com/doc/tutorial/functions2/
Last edited on
Topic archived. No new replies allowed.