13.6.3
来源:互联网 发布:软件测试包括哪些 编辑:程序博客网 时间:2024/05/16 10:13
13.55
void push_back(string &&s) { data->push_back(std::move(s)); }
13.56
Foo Foo::sorted() const & { Foo ret(*this); return ret.sorted();}
将会无限递归
因为ret是一个左值,ret.sorted() 调用的不是成员函数Foo Foo::sorted() &&,而是
Foo Foo::sorted() const &本身
13.57
Foo Foo::sorted() const & { return Foo(*this).sorted(); }
调用正确
13.58
#include <vector>#include <iostream>#include <algorithm>using std::vector; using std::sort;class Foo {public: Foo sorted() &&; Foo sorted() const &;private: vector<int> data;};Foo Foo::sorted() && { sort(data.begin(), data.end()); std::cout << "&&" << std::endl; // debug return *this;}Foo Foo::sorted() const & {// Foo ret(*this);// sort(ret.data.begin(), ret.data.end());// return ret; std::cout << "const &" << std::endl; // debug// Foo ret(*this);// ret.sorted(); // Exercise 13.56// return ret; return Foo(*this).sorted(); // Exercise 13.57}int main(){ Foo().sorted(); // call "&&" Foo f; f.sorted(); // call "const &"}
0 0
- 13.6.3
- 第十三章 13.6.3节练习
- 13.6.1
- 13.6.2
- Android优秀开源项目集合(不定时更新)13.6.3更新
- 13.6 第十三章小结
- 13.6 正则表达式
- 13.6 Interleaving String
- 13.6 第十三章小结
- 13.6节练习
- 13.6指向类成员的指针
- 谭浩强著《C程序设计(第二版)》习题13.6
- 第十三章 13.6.1节练习
- 第十三章 13.6.2节练习
- Java编程思想13.6-正则表达式
- 13.6 2013计算机视觉代码合集一
- 13.6 绕过缓冲区高速缓存:直接I/O
- 13.6 Thread类自定义线程类
- avpicture_fill的实现
- TODO:火热的集福,我这样看
- 运放电路正负反馈判断方法--瞬时极性法
- Java--Windows编码GBK的不可映射字符
- linux 系统简介
- 13.6.3
- the bag of words representation —— Python Data Science CookBook
- 如何优化Java垃圾回收机制
- Sudoku poj2676 (dfs)
- Redis数据持久化与事务
- Leetcode031--集合的所有子集
- 矩阵快速幂的JAVA实现
- Centos与mysql
- MYSQL性能优化的最佳20+条经验