文章分类 -  C++ Primer

C++ Primer英文版书籍
摘要:Exercises Section 16.1.1 Ex16.1 编译器用推断出的模板参数生成一个特定版本的函数,这个过程就叫做实例化。 Ex16.2 #include<iostream> #include<functional> using namespace std; template <type 阅读全文
posted @ 2022-10-14 18:43 astralcon 阅读(32) 评论(0) 推荐(0) 编辑
摘要:Exercises Section 15.2.1 Ex15.1 一个类的 virtual 成员可以被其派生类重写 Ex15.2 被 protected 修饰的类成员可以被该类的派生类访问,而被 private 修饰的类成员则不行。 Ex15.3 class Quote { public: Quote 阅读全文
posted @ 2022-10-14 18:43 astralcon 阅读(26) 评论(0) 推荐(0) 编辑
摘要:Exercises Section 14.1 Ex14.1 不同点:重载操作符必须至少有一个类类型或枚举类型的操作数;重载操作符不保证操作数的求值顺序。 相同点:有相同的优先级和结合性,操作数的数目不变。 Ex14.2 class Sales_data { friend ostream &opera 阅读全文
posted @ 2022-10-14 18:42 astralcon 阅读(58) 评论(0) 推荐(0) 编辑
摘要:Exercises Section 13.1.1 Ex13.1 copy constructor:第一个参数为类类型的引用,任何其他参数都有默认值。 在如下情况下使用拷贝构造函数: 用 = 定义变量 传递一个对象作为参数给非引用类型 函数的返回对象的类型为非引用返回类型 用括号初始化数组元素或聚合类 阅读全文
posted @ 2022-10-14 18:42 astralcon 阅读(47) 评论(0) 推荐(0) 编辑
摘要:Exercises Section 12.1.1 Ex12.1 // b1 和 b2 共享数据,故而 b1 和 b2 都有 4 个元素 StrBlob b1; { Strblob b2 = {"a", "an", "the"}; b1 = b2; b2.push_back("about"); } E 阅读全文
posted @ 2022-10-14 18:42 astralcon 阅读(45) 评论(0) 推荐(0) 编辑
摘要:Exercises Section 11.1 Ex11.1 map:关联容器,元素为键值对;map没有push_back;map的元素按照关键字来保存和访问 vector:顺序容器,元素为内置类型或者自定义类型;可以对vector调用排序算法;vector是按照元素在容器的位置保存和访问 Ex11. 阅读全文
posted @ 2022-10-14 18:41 astralcon 阅读(25) 评论(0) 推荐(0) 编辑
摘要:Exercises Section 10.1 Ex10.1 #include<iostream> #include<algorithm> #include<vector> using namespace std; int main() { int value; int number = 15; ve 阅读全文
posted @ 2022-10-14 18:41 astralcon 阅读(27) 评论(0) 推荐(0) 编辑
摘要:Exercises Section 9.1 Ex9.1 a) list 可能涉及中间插入操作 b) deque 涉及头部删除,尾部插入 c) vector 没有更好的选择 Exercises Section 9.2 Ex9.2 list<deque<int>> lqint; Exercises Se 阅读全文
posted @ 2022-10-14 18:40 astralcon 阅读(26) 评论(0) 推荐(0) 编辑
摘要:Exercises Section 8.1.2 Ex8.1 8.2 #include<iostream> #include<string> std::istream &read_Write(std::istream &is) { std::string s; while (is >> s) std: 阅读全文
posted @ 2022-10-14 18:40 astralcon 阅读(14) 评论(0) 推荐(0) 编辑
摘要:Exercises Section 7.1.1 Ex7.1 #include<iostream> #include<string> struct Sales_data { std::string bookNo; unsigned units_sold = 0; double revenue = 0. 阅读全文
posted @ 2022-10-14 18:39 astralcon 阅读(19) 评论(0) 推荐(0) 编辑
摘要:Exercises Section 6.1 Ex6.1 1. 参数是用来传递的,变量是通过定义得到的 2. 在调用过程中,有时候需要输入参数,此时参数会有值,可以直接传入;变量只有在赋值后才能使用 Ex6.2 a) // origin code 返回类型不匹配 int f() { string s; 阅读全文
posted @ 2022-10-14 18:39 astralcon 阅读(38) 评论(0) 推荐(0) 编辑
摘要:Exercises Section 5.1 Ex5.1 ; // null statement Ex5.2 // block { } Exercises Section 5.2 Ex5.4 a) while (string::iterator iter != s.end()) { /*... */ 阅读全文
posted @ 2022-10-14 18:37 astralcon 阅读(17) 评论(0) 推荐(0) 编辑
摘要:Exercises Section 4.1.2 Ex4.1 5 + 10 * 20 / 2 = 105 Ex4.2 a) *(vec.begin()) b) (*(vec.begin())) + 1 Exercises Section 4.2 Ex4.4 ((12 / 3) * 4) + (5 * 阅读全文
posted @ 2022-10-14 18:37 astralcon 阅读(17) 评论(0) 推荐(0) 编辑
摘要:Exercises Section 3.2.2 Ex3.2 // 一次读取一行 #include<iostream> #include<string> using namespace std; int main() { string line; while (getline(cin, line)) 阅读全文
posted @ 2022-10-14 18:35 astralcon 阅读(18) 评论(0) 推荐(0) 编辑
摘要:Exercise Section 2.1.1 Ex2.1 一个 long long 类型至少和 一个 long 类型一样大;一个 long 类型至少和一个 int 类型一样大;一个 int 类型至少和一个 short 类型一样大。 unsigned 类型不存在负数;signed 类型存在负数。 一个 阅读全文
posted @ 2022-10-14 18:33 astralcon 阅读(19) 评论(0) 推荐(0) 编辑
摘要:Preface 使用的书籍为《C++ Primer》第五版 英文版 Exercises Section 1.1 Ex1.2 Exercises Section 1.2 Ex1.3 Ex1.4 Ex1.5 Ex1.6 v1 后面多了一个冒号 Exercises Section 1.3 Ex1.7 Ex 阅读全文
posted @ 2022-10-14 18:31 astralcon 阅读(32) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示