quick question.. problem with complex<double>

1
2
53: error: no match for 'operator+' in '1 + std::operator* [with _Tp = double](((const std::complex<double>&)((const std::complex<double>*)(& c_unit))), ((const double&)((const double*)(& alpha))))'
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../include/c++/4.4.4/bits/stl_bvector.h:264: note: candidates are: std::_Bit_iterator std::operator+(ptrdiff_t, const std::_Bit_iterator&)


The line in question:
s_2 = (1 + c_unit*alpha)*( n + 0.5*h*r_1)*( e + 0.5*h*s_1);

It seems as though the problem is being caused by the addition in the first bracket?

But I'm really not sure..

The variables in question are declared as follows:
1
2
3
4
5
6
7
8
9
10
11
12
  double h;
  double alpha,p;

  double n, r_1,r_2,r_3,r_4;
  complex<double> e(0.5,0) , s_1,s_2,s_3,s_4;

  complex<double> c_unit(0.0,1.0);

  vector< complex<double> > n_;
  vector< complex<double> > e_;
  vector<double> t_;



I'm really not sure what the issue is, I've read around a bit and seen a
lot to do with 'operator overloading' etc. Having done similar
calculations in the past I can't really understand what the problem is in
this case...

.. any help appreciated :)
Last edited on
You could try this:
 
	s_2 = (1.0 + c_unit*alpha)*( n + 0.5*h*r_1)*( e + 0.5*h*s_1);

There is a difference between 1 which is type integer and 1.0 which is type double.
Last edited on
I honestly can't believe that that was the problem...


Why would it not work for an 'int'... the complex library doesn't work for 'int' I presume


thanks! :)
You declared the type of the complex to be double.rather than int. Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14

	int h;
	int alpha,p;

	int n, r_1,r_2,r_3,r_4;
	complex<int> e(0.5,0) , s_1,s_2,s_3,s_4;

	complex<int> c_unit(0.0,1.0);

	vector< complex<int> > n_;
	vector< complex<int> > e_;
	vector<int> t_;

	s_2 = (1 + c_unit*alpha)*( n + h*r_1/2)*( e + h*s_1/2);
Last edited on
sorry, what I meant in my previous post was that you fixed my problem!

I was just surprised that the fix had been so easy.. :)

thanks again!
Topic archived. No new replies allowed.