Mixing complex numbers and ints
Gabriel Dos Reis
gdr@codesourcery.com
Wed Dec 6 11:25:00 GMT 2000
Peter Bienstman <Peter.Bienstman@rug.ac.be> writes:
| Hi,
|
| The following program
|
| #include <complex>
|
| int main()
| {
| std::complex<double> a(1,1);
| a + 1;
That is bogus. It should read a + 1.0
| }
|
| produces
|
| c.cpp: In function `int main()':
| c.cpp:6: no match for `std::complex<double>& + int' operator
|
| This worked in 2.95.
The library shipped with 2.95 isn't conforming.
| ... Using doubles instead of ints does work.
Yes, by design.
| Is this a true regression or just a correct implementation of stricter
| promotion rules imposed by the standard?
That is not a regression. It is just a correct implementation of the
Standard which says:
template<typename T> complex<T> operator+(const complex<T>&, const T&)
So use of that operator triggers template-argument deduction which
doesn't take most standard conversions into account. You need to be
explicit about type issues.
-- Gaby
CodeSourcery, LLC http://www.codesourcery.com
More information about the Libstdc++
mailing list