C++ (Qt)class TANumber{public: virtual ~Number() {} virtual TANumber& operator+(TANumber&) = 0;//...};
Cstruct SomeNumber; struct BaseNumber { virtual const BaseNumber& operator + (const BaseNumber&) const = 0; protected: virtual const BaseNumber& add_to(const BaseNumber&) const {throw std::bad_cast();} virtual const SomeNumber& add_to(const SomeNumber&) const = 0;};struct SomeNumber : BaseNumber { virtual const SomeNumber& operator + (const BaseNumber& other) const { return other.add_to(*this); } protected: virtual const SomeNumber& add_to(const SomeNumber&) const;};
C++ (Qt)class Number{ /* ... ... ... */public: virtual Number& operator =(Number &n) = 0; virtual Number& operator +(Number &n) = 0; /* ... ... ... */}; class PNumber : public Number{ /* ... ... ... */ Number& operator =(Number &p1); Number& operator +(Number &p1); /* ... ... ... */}; Number& PNumber::operator +(PNumber &p1){ PNumber *pn; Number *n = &p1; pn = dynamic_cast<PNumber *>(n); pn->number += this->number; return *pn;}
C++ (Qt)Number& PNumber::operator +(PNumber &p1)