Multiplying complex with constant in C++
- by Atilla Filiz
The following code fails to compile
#include <iostream>
#include <cmath>
#include <complex>
using namespace std;
int main(void)
{
const double b=3;
complex <double> i(0, 1), comp;
comp = b*i;
comp=3*i;
return 0;
}
with
error: no match for ‘operator*’ in ‘3 * i’
What is wrong here, why cannot I multiply with immediate constants?