I’m having a problem with one of my functions within a template class.
template <class T>
T complex<T>::returnMod()
{
T mod(0);
mod = sqrt(pow(re,2.0) + pow(im,2.0));
return mod;
}
I get the error: ‘warning C4244: ‘=’ : conversion from ‘double’ to ‘int’, possible loss of data’ for the line in bold. How can I tell the compiler to use the type called for each class object? I create two different types of complex number, some with int and some with double. Thank you.
The problem seems to be that you are instantiating
complexwith typeint, and the compiler is doing exactly what you asked for.Tis int, and the expressionsqrtreturns adoubleso it has to convert.I am not sure what you meant with How can I tell the compiler to use the type called for each class object?, but this is expected behavior.