guestgulkan:
You can just specialise for each complex class you want |
Yes, of course that would work. But that way, I've got to do a specialization for complex<double>, other for complex<float>, other for complex<int>, and so on... That is totally opposed to the spirit of templates. My question was if there is a way to do it with only one specialization.
L B:
Well, the first complex<T> is supposed to be the return type, Vector<complex<T> >:: the scope (the operator is a member function), and template<class T> is declaring as a template, because I want the function to work on all the complex<T> types. I already now that is not the right code, I'm just asking how to fix it.
why would complex numbers need a specialization? |
Complex numbers need a specialization for a mathematical reason, not for a overloading one: real dot product of two vectors
v = (v
1, ... v
n) and
w = (w
1, ... w
n) is the sum of the terms v
1·w
1, while complex dot product is the sum of the terms v
1·(w
1)
* (where
* means complex conjugation). And I can't overload conjugation because is only a function defined for complex<>, not for int, float or double