| 23 | }; |
| 24 | |
| 25 | class ScalarWithExceptions |
| 26 | { |
| 27 | public: |
| 28 | ScalarWithExceptions() { init(); } |
| 29 | ScalarWithExceptions(const float& _v) { init(); *v = _v; } |
| 30 | ScalarWithExceptions(const ScalarWithExceptions& other) { init(); *v = *(other.v); } |
| 31 | ~ScalarWithExceptions() { |
| 32 | delete v; |
| 33 | instances--; |
| 34 | } |
| 35 | |
| 36 | void init() { |
| 37 | v = new float; |
| 38 | instances++; |
| 39 | } |
| 40 | |
| 41 | ScalarWithExceptions operator+(const ScalarWithExceptions& other) const |
| 42 | { |
| 43 | countdown--; |
| 44 | if(countdown<=0) |
| 45 | throw my_exception(); |
| 46 | return ScalarWithExceptions(*v+*other.v); |
| 47 | } |
| 48 | |
| 49 | ScalarWithExceptions operator-(const ScalarWithExceptions& other) const |
| 50 | { return ScalarWithExceptions(*v-*other.v); } |
| 51 | |
| 52 | ScalarWithExceptions operator*(const ScalarWithExceptions& other) const |
| 53 | { return ScalarWithExceptions((*v)*(*other.v)); } |
| 54 | |
| 55 | ScalarWithExceptions& operator+=(const ScalarWithExceptions& other) |
| 56 | { *v+=*other.v; return *this; } |
| 57 | ScalarWithExceptions& operator-=(const ScalarWithExceptions& other) |
| 58 | { *v-=*other.v; return *this; } |
| 59 | ScalarWithExceptions& operator=(const ScalarWithExceptions& other) |
| 60 | { *v = *(other.v); return *this; } |
| 61 | |
| 62 | bool operator==(const ScalarWithExceptions& other) const |
| 63 | { return *v==*other.v; } |
| 64 | bool operator!=(const ScalarWithExceptions& other) const |
| 65 | { return *v!=*other.v; } |
| 66 | |
| 67 | float* v; |
| 68 | static int instances; |
| 69 | static int countdown; |
| 70 | }; |
| 71 | |
| 72 | ScalarWithExceptions real(const ScalarWithExceptions &x) { return x; } |
| 73 | ScalarWithExceptions imag(const ScalarWithExceptions & ) { return 0; } |