What's the right way to overload the stream operators << >> for my class?

后端 未结 4 1669
礼貌的吻别
礼貌的吻别 2020-12-19 09:49

I\'m a bit confused about how to overload the stream operators for my class in C++, since it seems they are functions on the stream classes, not on my class. What\'s the no

4条回答
  •  情书的邮戳
    2020-12-19 10:33

    Your implementation is fine. The only additional step you need to perform is to declare your operator as a friend in Thing:

    class Thing {
    public:
      friend istream& operator>>(istream&, Thing&);
      ...
    }
    

提交回复
热议问题