Heloo, I’m having trouble with overloading the / operator in a member function within a template class. I get the error ‘error C2805: binary ‘operator /’ has too few parameters’ but I think I’m giving the operator enough parameters. Here is part of my header file code
template <class T>
typename complex<T>::complex operator/(complex<T> &c)
{
complex temp;
temp.re = (re*c.getRe() + im*c.getIm())/(pow(c.getRe(),2)+pow(c.getIm(),2));
temp.im = (im*c.getRe() - re*c.getIm())/(pow(c.getRe(),2)+pow(c.getIm(),2));
return temp;
}
My function declaration is given below
T operator/(complex<T> &c);
My declaration is indside the class template and the declaration outside, but within the same namespace. If you need the whole code please let me know. Thank you.
You are missing the class prefix in the operator definition:
Also, you declared the operator as returning
T– why are you returningcomplexin the definition?