I'll tell you c++ is phenomenally difficult for a beginner. I need to extract the real part from a complex number. My compiler is g++ in Ubuntu 12.04.
Nothing I have tried worked so far and I googled and googled. It is just ridiculous. Let say the number is complC, then complC.real() does not work, std::real (complC) does not work either. Needless to day I tried numerous other variants. This is a simple operation. Why is it made so difficult?
#include "fft.h"
#include <math.h>
#include <fstream> // std::ofstream
#include <complex>
int main ()
{
std::ofstream outFileInput,outFileOutput;
complex Input[1024]=0, Output[1024]=0;
complex valueC;
int N=1024;
double xx;
double welshWindow(int n, int N);
outFileInput.open ("cppFFTinp.dat");
outFileOutput.open("cppFFTout.dat");
for (int jj = 0; jj<N-1; jj++)
{
xx = welshWindow(jj,N);
valueC = complex(xx,0);
Input[jj] = valueC;
outFileInput << jj << " " << xx << std::endl;
}
CFFT::Forward (Input,Output,N);
for (int jj = 0; jj<N-1; jj++)
{
valueC = Output[jj];
xx = std::real(valueC); // this statement does not compile
outFileOutput << jj << " " << xx << std::endl;
}
} // main
If I remove the statement marked // This statement does not compile, the file compiles and I can run it. As I said, I need to extract the real part of the complex number in question. In fortran it is elementary. Here it is a monumental problem. It is simply gross.
If I leave the statement in question and to g++ fft.cpp I get these errors:
1 2 3 4 5
fft.cpp: In function ‘int main()’:
fft.cpp:33:28: error: no matching function for call to ‘real(complex&)’
fft.cpp:33:28: note: candidates are:
/usr/include/c++/4.6/complex:545:5: note: template<class _Tp> _Tp& std::real(std::complex<_Tp>&)
/usr/include/c++/4.6/complex:550:5: note: template<class _Tp> const _Tp& std::real(const std::complex<_Tp>&)
33 is the number line of that statement. What can I do about the "candidates?" I think my code already complies with this template.
Thanks, but that leads to terrible problems. In the end if I include complex.h I will get five terminals worth of errors. I've tried it before. When I included these definitions you posted in the file I got a bunch of errors also. I am not sure it is worth even trying to post them unless requested.
There should be a SIMPLE way to get the real part of a complex number. WHAT IS GOING ON? Anybody knows how to do it?
I'm sorry you're having such problems. I see your other thread on the compilation problem you're having.
I copy/pasted the code for the complex.h and complex.cpp files to my Code::Blocks compiler
and tried this:
The following compiles on my box. Of course, since you didn't provide the definition for double welshWindow(), I had to comment out line 18 and only get zeros as output.