From: Pat on 2 Dec 2009 16:02 I'm using the complex<double> template to define some complex variables. If I multiply a complex variable by a constant (5) like this: complex z2 = 5*z1; I get an error (no match for 'operator*' in '5*z1'). But if I add a decimal point, complex z2 = 5.*z1; it compiles fine. Why is that?
From: Ben Bacarisse on 2 Dec 2009 16:58 Pat <pkelecy@_REMOVETHIS_gmail.com> writes: > I'm using the complex<double> template to define some complex > variables. If I multiply a complex variable by a constant (5) like > this: > > complex z2 = 5*z1; > > I get an error (no match for 'operator*' in '5*z1'). But if I add a > decimal point, > > complex z2 = 5.*z1; > > it compiles fine. Why is that? 5 is a constant expression of type int. 5. is a constant expression of type double. Is that enough?  Ben.
From: Pat on 3 Dec 2009 15:38 Ben Bacarisse wrote: > Pat <pkelecy@_REMOVETHIS_gmail.com> writes: > >> I'm using the complex<double> template to define some complex >> variables. If I multiply a complex variable by a constant (5) like >> this: >> >> complex z2 = 5*z1; >> >> I get an error (no match for 'operator*' in '5*z1'). But if I add a >> decimal point, >> >> complex z2 = 5.*z1; >> >> it compiles fine. Why is that? > > 5 is a constant expression of type int. 5. is a constant expression > of type double. Is that enough? > Yes. That was my guess, but I thought I would ask just to be sure. Thanks!
From: Fred on 3 Dec 2009 17:53 On Dec 3, 12:38 pm, Pat <pkelecy@_REMOVETHIS_gmail.com> wrote: > Ben Bacarisse wrote: > > Pat <pkelecy@_REMOVETHIS_gmail.com> writes: > > >> I'm using the complex<double> template to define some complex > >> variables. If I multiply a complex variable by a constant (5) like > >> this: > > >> complex z2 = 5*z1; > > >> I get an error (no match for 'operator*' in '5*z1'). But if I add a > >> decimal point, > > >> complex z2 = 5.*z1; > > >> it compiles fine. Why is that? > > > 5 is a constant expression of type int. 5. is a constant expression > > of type double. Is that enough? > > Yes. That was my guess, but I thought I would ask just to be sure. > The real question: Is there a specific reason that the complex class has no +*/ overloaded operators with (complex,int) and (int,complex) signatures, other than it just wasn't done?  Fred K

Pages: 1 Prev: Compile and write C++ code on a Netbook? Next: Using friend functions to overload operators 