#ifndef SAFE_INT_H #define SAFE_INT // a class that behaves like an int but will throw an exception when // dividing by zero, or overflow/underflow beyond the limits of int class safe_int { private: int value; void add_pos(int i); void add_neg(int i); int sign(int i) const; public: safe_int(int v); operator int() const; safe_int operator+(); safe_int operator-(); safe_int& operator+=(const safe_int& i); safe_int& operator-=(const safe_int& i); safe_int& operator*=(const safe_int& i); safe_int& operator/=(const safe_int& i); safe_int operator+(const safe_int& i) const; safe_int operator-(const safe_int& i) const; safe_int operator*(const safe_int& i) const; safe_int operator/(const safe_int& i) const; class divide_by_zero { }; class overflow { }; class underflow { }; }; #endif