Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <string>
- using namespace std;
- class MyTypeA
- {
- public:
- MyTypeA(int i) : _i(i) {};
- virtual ~MyTypeA() {};
- string getStr() const { return to_string(_i); }
- private:
- int _i;
- };
- class MyTypeB
- {
- public:
- MyTypeB(int i) : _i(i) {};
- virtual ~MyTypeB() {};
- string getStr() const { return to_string(_i); }
- private:
- int _i;
- };
- class Message : public ostringstream
- {
- public:
- Message() {};
- virtual ~Message() {};
- Message& operator <<(const MyTypeA &a) {
- return *this << a.getStr();
- };
- Message& operator <<(const MyTypeB &b) {
- return *this << b.getStr();
- };
- template<class T>
- Message& operator <<(const T &t)
- {
- (std::ostringstream&)(*this) << t;
- return *this;
- }
- };
- int main()
- {
- MyTypeA a(10);
- MyTypeA b(-10);
- Message m;
- m << a << "-" << b; // This works just fine!
- m << a << "-" << b << endl; // Ba dumm tss
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement