Wrapper Classes for Primitive Data Types
问题 In designing a solution, sometimes it may be convenient to provide wrapper classes for primitive data types. Consider a class that represents a numeric value, be it a double , a float , or an int . class Number { private: double val; public: Number(int n) : val(n) { } Number(float n) : val(n) { } Number(double n) : val(n) { } // Assume copy constructors and assignment operators exist Number& add(const Number& other) { val += other.val; return *this; } int to_int() const { return (int) val; }