Hi, I need to implement a numerical algorithm using complex numbers. But, I haven't get that working yet, because I have problems with header files. (I haven't used those before) I have tried, for instance, something like this
http://www.cplusplus.com/forum/general/23930/ but still I couldn't get my code working. Basically, what the code should do is to evaluate (eval) complex function (fun) at point z. Finally it should return a complex number. Here is the code
//main.cpp
#include <iostream>
#include <complex>
#include "cplxOp.h"
using namespace std;
typedef complex<double> cplx;
typedef cplx (*function)(cplx );
cplx fun(cplx z){
return cplx(2,0)*z;
}
int main(){
ComplexOper Operation;
Operation.z = cplx(1,1);
Operation.fun = fun;
cout << "Complex number = " << Operation.eval << endl;
return 0;
}
//cplxOp.h
#ifndef CPLXOP_H
#define CPLXOP_H
#include <complex>
typedef cplx<double> cplx;
typedef cplx (*function)(cplx);
ComplexOper{
public:
cplx z;
function fun;
cplx eval(function fun,cplx z);
};
#endif
//cplxOp.cpp
#include <complex>
#include "cplxOp.h"
using namespace std;
cplx eval(function fun, cplx z){
return fun(z);
}
Errors:
cplxOp.h:4:9: error: ‘cplx’ does not name a type
cplxOp.h:5:14: error: ISO C++ forbids declaration of ‘cplx’ with no type [-fpermissive]
cplxOp.h:5:14: error: typedef ‘cplx’ is initialized (use decltype instead)
cplxOp.h:5:16: error: ‘function’ was not declared in this scope
cplxOp.h:6:1: error: ‘ComplexOper’ does not name a type