首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

【C++】运算符重载 ⑧ ( 左移运算符重载 | 友元函数 成员函数 实现运算符重载 | 类对象 使用 左移运算符 )

cout 标准输出流 , 参数中是引用类型 ; cout << s1 右操作数是 Student s 类对象 , 参数中是引用类型 ; operator<<(ostream& out, Student...& s) 再后 , 根据业务完善返回值 , 返回值可以是 引用 / 指针 / 元素 ; 此处返回 void 即可 ; 返回 ostream& 引用类型 , 是为了支持链式调用 cout << s1 <...< endl; ostream& operator<<(ostream& out, Student& s) 最后 , 实现函数体 , 编写具体的运算符操作业务逻辑 ; // 全局函数 中实现 Student...左移运算符重载 // 返回 ostream& 引用类型 , 是为了支持链式调用 cout << s1 << endl; ostream& operator<<(ostream& out, Student...& 引用类型 , 是为了支持链式调用 cout << s1 << endl; ostream& operator<<(ostream& out, Student& s) { // 在函数体中将 Student

23610

从零开始学C++之STL(十):迭代器适配器{(插入迭代器back_insert_iterator)、IO流迭代器(istream_iterator、ostream_iterator)}

再来看ostream_iterator 的源码: // TEMPLATE CLASS ostream_iterator template<class _Ty,     class _Elem = char...,     class _Traits = char_traits >     class ostream_iterator         : public _Outit     {   ...; #endif     ostream_iterator(ostream_type& _Ostr,         const _Elem *_Delim = 0)         : _Myostr...= 0)             *_Myostr << _Mydelim;         return (*this);         }     ostream_iterator<_Ty, ... *_Myostr;  // pointer to output stream     }; ostream_iterator 类也有两个成员,一个是输出流对象指针,一个是字符串指针,看上面的copy

1K00
领券