摘要: 程序:允许用户在一个给定文件中查询单词,查询结果是单词在文件中出现的次数及其所在行的列表。如果一个单词在一行中出现多次,此行只列出一次。 头文件: 源文件: 阅读全文
posted @ 2017-11-17 21:32 GGBeng 阅读(268) 评论(0) 推荐(0) 编辑
摘要: #include #include #include #include #include #include using namespace std; class StrBlobPtr; class StrBlob { friend class StrBlobPtr; public: using size_type = vector::size_type; ... 阅读全文
posted @ 2017-11-17 20:07 GGBeng 阅读(620) 评论(0) 推荐(0) 编辑
摘要: 优势:即使StrBlob类对象被销毁,vector并不一定会被销毁! 适用:多个类对象间共享数据 阅读全文
posted @ 2017-11-17 17:51 GGBeng 阅读(389) 评论(0) 推荐(0) 编辑
摘要: 一、关键 每个shared_ptr所指向的对象都有一个引用计数,它记录了有多少个shared_ptr指向自己 shared_ptr的析构函数:递减它所指向的对象的引用计数,如果引用计数变为0,就会销毁对象并释放相应的内存 引用计数的变化:决定权在shared_ptr,而与对象本身无关 二、引用计数初 阅读全文
posted @ 2017-11-17 17:26 GGBeng 阅读(7049) 评论(1) 推荐(2) 编辑
摘要: #include #include #include using namespace std; map> binops; class multiply { public: int operator()(int a, int b) const { return a * b; } }; int add(int a, int b) { return a + b; } auto di... 阅读全文
posted @ 2017-11-17 13:26 GGBeng 阅读(209) 评论(0) 推荐(0) 编辑
摘要: 一、关键 内存分配:union各成员共享一段内存空间,即任一时刻只能有一个成员可以有值(故分配给一个union对象的存储空间至少要能容纳它的最大的数据成员) union与类:union是一种节省空间的类,但并非类的所有特性都适用于它(如其不能有引用类型的成员) 匿名union:其成员的作用域与它的作 阅读全文
posted @ 2017-11-17 11:36 GGBeng 阅读(352) 评论(0) 推荐(0) 编辑