diff options
Diffstat (limited to 'Examples/python/operator/example.h')
-rw-r--r-- | Examples/python/operator/example.h | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Examples/python/operator/example.h b/Examples/python/operator/example.h new file mode 100644 index 0000000..4da6a23 --- /dev/null +++ b/Examples/python/operator/example.h @@ -0,0 +1,36 @@ +/* File : example.h */ +#include <math.h> + +class Complex { +private: + double rpart, ipart; +public: + Complex(double r = 0, double i = 0) : rpart(r), ipart(i) { } + Complex(const Complex &c) : rpart(c.rpart), ipart(c.ipart) { } + Complex &operator=(const Complex &c) { + rpart = c.rpart; + ipart = c.ipart; + return *this; + } + Complex operator+(const Complex &c) const { + return Complex(rpart+c.rpart, ipart+c.ipart); + } + Complex operator-(const Complex &c) const { + return Complex(rpart-c.rpart, ipart-c.ipart); + } + Complex operator*(const Complex &c) const { + return Complex(rpart*c.rpart - ipart*c.ipart, + rpart*c.ipart + c.rpart*ipart); + } + Complex operator-() const { + return Complex(-rpart, -ipart); + } + + double re() const { return rpart; } + double im() const { return ipart; } +}; + + + + + |