/tags/rel-1-3-24/SWIG/Examples/ruby/operator/example.h
C++ Header | 36 lines | 28 code | 7 blank | 1 comment | 0 complexity | 61c61e3db6a1c5379ed98540e5b11d84 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
1/* File : example.h */ 2#include <math.h> 3 4class Complex { 5private: 6 double rpart, ipart; 7public: 8 Complex(double r = 0, double i = 0) : rpart(r), ipart(i) { } 9 Complex(const Complex &c) : rpart(c.rpart), ipart(c.ipart) { } 10 Complex &operator=(const Complex &c) { 11 rpart = c.rpart; 12 ipart = c.ipart; 13 return *this; 14 } 15 Complex operator+(const Complex &c) const { 16 return Complex(rpart+c.rpart, ipart+c.ipart); 17 } 18 Complex operator-(const Complex &c) const { 19 return Complex(rpart-c.rpart, ipart-c.ipart); 20 } 21 Complex operator*(const Complex &c) const { 22 return Complex(rpart*c.rpart - ipart*c.ipart, 23 rpart*c.ipart + c.rpart*ipart); 24 } 25 Complex operator-() const { 26 return Complex(-rpart, -ipart); 27 } 28 29 double re() const { return rpart; } 30 double im() const { return ipart; } 31}; 32 33 34 35 36