git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10290 626c5289-ae23-0410-ae9c-e8d60b6d4f22
36 lines
878 B
C++
36 lines
878 B
C++
/* File : example.h */
|
|
#include <math.h>
|
|
|
|
class ComplexVal {
|
|
private:
|
|
double rpart, ipart;
|
|
public:
|
|
ComplexVal(double r = 0, double i = 0) : rpart(r), ipart(i) { }
|
|
ComplexVal(const ComplexVal &c) : rpart(c.rpart), ipart(c.ipart) { }
|
|
ComplexVal &operator=(const ComplexVal &c) {
|
|
rpart = c.rpart;
|
|
ipart = c.ipart;
|
|
return *this;
|
|
}
|
|
ComplexVal operator+(const ComplexVal &c) const {
|
|
return ComplexVal(rpart+c.rpart, ipart+c.ipart);
|
|
}
|
|
ComplexVal operator-(const ComplexVal &c) const {
|
|
return ComplexVal(rpart-c.rpart, ipart-c.ipart);
|
|
}
|
|
ComplexVal operator*(const ComplexVal &c) const {
|
|
return ComplexVal(rpart*c.rpart - ipart*c.ipart,
|
|
rpart*c.ipart + c.rpart*ipart);
|
|
}
|
|
ComplexVal operator-() const {
|
|
return ComplexVal(-rpart, -ipart);
|
|
}
|
|
|
|
double re() const { return rpart; }
|
|
double im() const { return ipart; }
|
|
};
|
|
|
|
|
|
|
|
|
|
|