I've been trying to make a FFT with wxwidgets on linux, but I am not very familiar with C++. I've tried two approaches both without any lucky, and I've been reading all about the errors looking for similar problems and I still don't understand what's wrong.
First Approach (everything inside the class)
#include <valarray>
#include <complex>
#include <sstream>
#include <iterator>
#include <vector>
class do_fft
{
public:
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
do_fft();
virtual ~do_fft();
private:
const static double PI = 3.141592653589793238460;
CArray x;
void setDados(CArray v)
{
CArray x = v;
}
CArray getFFT()
{
void fft(CArray& x)
{ //line 27
const size_t N = x.size();
if (N <= 1) return;
// divide
CArray par = x[std::slice(0, N/2, 2)];
CArray impar = x[std::slice(1, N/2, 2)];
// conquistar
fft(par);
fft(impar);
// combinar
for (size_t k = 0; k < N/2; ++k)
{
Complex t = std::polar(1.0, -2 * PI * k / N) * impar[k];
x[k ] = par[k] + t;
x[k+N/2] = par[k] - t;
}
}
fft(x);
return x;
} //line 49
} fftd;
Errors when trying to compile:
do_fft.h|49|error: expected ‘;’ after
class definition| do_fft.h||In member function ‘do_fft::CArray
do_fft::getFFT()’:| do_fft.h|27|error: a function-definition is not
allowed here before ‘{’ token| do_fft.h|49|error: expected ‘}’ at end
of input| do_fft.h|49|warning: no return statement in function
returning non-void
Second Approach - Separate declarations from methods:
class do_fft
{
public:
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
// do_fft();
// virtual ~do_fft();
private:
const static double PI = 3.141592653589793238460;
CArray x;
void setDados(CArray v);
CArray getFFT();
} fftd;
do_fft.cpp|3|error: ISO C++ forbids declaration of ‘setDados’ with no type [-fpermissive]|
do_fft.cpp|3|error: prototype for ‘int do_fft::setDados(do_fft::CArray)’ does not match any in class ‘do_fft’|
do_fft.h|19|error: candidate is: void do_fft::setDados(do_fft::CArray)| do_fft.cpp|8|error: ‘getFFT’ in ‘class do_fft’ does not name a type| ||=== Build finished: 4 errors, 0 warnings ===|
My question is: what are the concepts that I am messing around and what would be the proper way to handle this ?
EDIT: Other question-> what does "virtual ~do_fft();" this line? (the IDE inserted it when creating the class)