From: Pat on
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
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
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
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