struct AllNumber { const AllNumber operator + (const AllNumber& other) const { return AllNumber(val.get()->add(other.val.get())); } private: std::auto_ptr<Number> val;};
C++ (Qt)struct CFractNumber : public CBaseNumber { CFractNumber & operator + (const CBaseNumber & other) const { assert(dynamoc_cast <const CFactNumber *> &other) != 0); CFractNumber & result = mBuf[mBufCount]; result = *this; mBufCount = (mBufCount + 1) % BUF_SIZE; return result += other; } private: static int mBufCount = 0; static CFractNumber mBuf[BUF_SIZE]; enum { BUF_SIZE = 256, };};
C++ (Qt)c = a + b;
C++ (Qt)AbstractNumber *n1 = new RealNumber(3.14);AbstractNumber *n2 = new RealNumber(2.71); *n1 = *n2 + *n1;
C++ (Qt)RealNumber n1(3.14);RealNumber n2(2.71); n1 = n2 + n1;