warning: assignment to `int' from `double'
Ralf W. Grosse-Kunstleve
rwgk@cci.lbl.gov
Wed Feb 27 15:27:00 GMT 2002
> > operator+= etc. for operations on arrays. The array
> > element types can be custom types with overloaded
> > operators. Any cast buried in the array operator+= would
> > interfere with the semantics of the overloaded custom
> > operators.
>
> I'm not sure why this is relevant; the issue is implicit conversions,
> isn't it?
Consider an idealized array operator+=:
template <typename ElementType1,
typename ElementType2>
std::vector<ElementType1>&
operator+=(std::vector<ElementType1>& a1,
const std::vector<ElementType1>& a2) {
for(std::size_t i=0;i<a1.size();i++) a1[i] += a2[i];
return a1;
}
For built-in types this would be fine:
a[i] += ElementType1(a2[i]);
But for custom types with potentially multiple overloads
for operator+= this construct would result in unexpected
behavior.
> > gcc 3.0.x (incl. 3.0.4) is the only compiler that issues
> > the warning above. (I am also using various EDG derivatives
> > and Codewarrior.)
>
> not a strong argument; you need to reference the standard.
If the standard demands a warning it is counter-productive
in my case. I wish it would be possible to selectively
suppress the warning.
Thanks,
Ralf
More information about the Gcc
mailing list