Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class T>
- class Operand;
- template <>
- class Operand <std::string>
- {
- std::string value;
- public:
- Operand() {}
- Operand(std::string initValue)
- {
- value = initValue;
- }
- Operand <std::string> operator+(Operand<std::string> const &b) const
- {
- Operand<std::string> str(*this);
- str.setValue(str.getValue() + b.getValue());
- return str;
- }
- Operand <std::string> operator+(Operand<int> const &b) const;
- Operand <std::string> operator*(Operand<int> const &b) const;
- std::string getValue() const
- {
- return value;
- }
- void setValue(std::string initValue)
- {
- value = initValue;
- }
- };
- template <class T>
- class Operand
- {
- T value;
- public:
- Operand() {}
- Operand(T initValue)
- {
- value = initValue;
- }
- Operand<T> operator-(Operand<T> const &b) const
- {
- Operand<T> integ(*this);
- integ.setValue(integ.getValue() - b.getValue());
- return integ;
- }
- Operand<T> operator/(Operand<T> const &b) const
- {
- Operand<T> integ(*this);
- integ.setValue(integ.getValue() / b.getValue());
- return integ;
- }
- Operand<T> operator+(Operand<T> const &b) const
- {
- Operand<T> integ(*this);
- integ.setValue(integ.getValue() + b.getValue());
- return integ;
- }
- /*Operand<std::string> operator+(Operand<std::string> const &b) const
- {
- Operand<std::string> str(std::to_string(this->getValue()));
- str.setValue(str.getValue() + b.getValue());
- return str;
- }*/
- Operand<T> operator*(Operand<T> const &b) const
- {
- Operand<T> integ(*this);
- integ.setValue(integ.getValue() * b.getValue());
- return integ;
- }
- Operand<std::string> operator*(Operand<std::string> const &b) const
- {
- Operand<std::string> str(b);
- int n = this->getValue();
- std::string strPart = str.getValue();
- while (n--)
- {
- str.setValue(str.getValue() + strPart);
- }
- return str;
- }
- T getValue() const
- {
- return value;
- }
- void setValue(T initValue)
- {
- value = initValue;
- }
- };
- Operand<std::string> Operand<std::string>::operator+(const Operand<int>& b) const
- {
- Operand<std::string> str(*this);
- str.setValue(str.getValue() + std::to_string(b.getValue()));
- return str;
- }
- Operand<std::string> Operand<std::string>::operator*(const Operand<int>& b) const
- {
- Operand<std::string> str(*this);
- int n = b.getValue();
- std::string strPart = str.getValue();
- while (n--)
- {
- str.setValue(str.getValue() + strPart);
- }
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement