最近在恶补OOP相关知识,很遗憾学校的课没选上,于是只能上网购进C++Primer一本,开始重学C++之旅。。。

(壮哉我大ZJU,网购半天到货XDD)

学习路线

7.类->13.类设计者的工具->15.面向对象程序设计

总的来说,C++Primer的章节编排顺序是很合理的。有些教材习惯上来就讲虚函数,继承,恰恰缺乏对有关问题的引导,造成学完后半懂不懂的情况。

7.类

类的特性,成员函数,友元函数,构造函数简介

13.类设计者的工具

拷贝构造函数,拷贝赋值运算符,析构函数,内存管理类,合成拷贝控制的时机,三/五法则,使用默认/删除函数,移动构造函数,移动赋值运算符,右值引用,智能指针shared_ptr<>

[以上两章均未涉及继承]

15.面向对象程序设计

#include <iostream>
#include <vector>
#define DEBUG stdio
#include "debug/debug.h"
using namespace debug;
using namespace std;
class A
{
public:
A(): tag(count++) { println("A%d()", tag); }
A(const A& a): tag(count++) { println("A%d(const A%d&)", tag, a.tag); }
A(A&& a): tag(count++) { println("A%d(A%d&&)", tag, a.tag); }
A& operator = (const A& a) { println("A%d& operator = (const A%d&)", tag, a.tag); }
A& operator = (A&& a) { println("A%d& operator = (A%d&&)", tag, a.tag); }
~A() { println("~A%d()", tag); }
public:
void func() { println("A::func()"); }
void func(int) { println("A::func(int)"); } virtual void f() { println("A::f()"); }
virtual void g() { println("A::g()"); }
virtual void h() { println("A::h()"); }
private:
static int count;
const int tag;
}; int A::count = 0; class B: public A
{
public:
B() = default;
B(const B&) = default;
public:
void func() { println("B::func()"); } void f() override { println("B::f()"); }
virtual void h() { println("B::h()"); }
}; int main()
{
A a;
B b;
A *p = &b;
p->f(); // virtual
p->g(); // virtual
p->h(); // virtual
p->func(1);
p->func();
}
A0()
A1()
B::f()
A::g()
B::h()
A::func(int)
A::func()
~A1()
~A0()
#include <iostream>
#include <vector>
#define DEBUG stdio
#include "debug/debug.h"
using namespace std;
using namespace debug; struct A
{
A() { cout << "A" << endl;}
A(const A&) { cout << "const A&" << endl;}
A(A&&) { cout << "A&&" << endl; }
A& operator = (const A&) { cout << "=const A&" << endl;}
A& operator = (A&&) { cout << "=A&&" << endl; }
virtual ~A() { cout << "~A" << endl; }
}; class B : public A
{
public:
B() { cout << "B" << endl; }
B(int) { cout << "B(int)" << endl; }
B(const B& v): A(v) { cout << "const B&" << endl; }
B(B&& v): A(v) { cout << "B&&" << endl; }
B& operator = (const B&) { cout << "=const B&" << endl; }
B& operator = (B&&) { cout << "=B&&" << endl; }
~B() override { cout << "~B" << endl; }
}; int main()
{
vector<B> vec;
vec.push_back(B());
//b.f(1);
}
A
B
const A&
B&&
~B
~A
~B
~A

最新文章

  1. 针对Excel的vbs操作
  2. DBCC DROPCLEANBUFFERS失效了?
  3. iOS socket TCP UDP
  4. 通过底层AVR方法实现SPI数据传输
  5. 6/19 sprint3 看板和燃尽图的更新
  6. C++用new和不用new创建类对象区别
  7. 脚踏实地学C#2-引用类型和值类型
  8. centos常用命令
  9. Linux查看CPU和内存使用情况【转】
  10. 20ms Ac Code
  11. 【微信小程序开发】快速开发一个动态横向导航模板并使用
  12. IntelliJ IDEA下Maven SpringMVC+Mybatis入门搭建例子
  13. 并发库应用之十二 &amp; 常用集合问题汇总
  14. Python数据结构应用5——排序(Sorting)
  15. 最近学习的 Node.js 基础:安装、环境配置、forever
  16. python - 发送带各种类型附件的邮件
  17. Win7 SP1 64位 旗舰版 IE8 快速稳定 纯净优化 无人值守 自动激活 20180604
  18. spring重要知识点总结
  19. C# 语法四 修饰符
  20. Deeplab v3+的结构代码简要分析

热门文章

  1. 转载-------makefile 使用总结
  2. qt 工具下的dump工具导出文档出现异常解决方案
  3. 基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。
  4. ASP.NET MVC 中将FormCollection与实体间转换方法
  5. 自己用C语言写dsPIC / PIC24 serial bootloader
  6. Orcle基本语句(六)
  7. tomcat manager配置
  8. 转载:reactor模式学习
  9. javascript知识点总结----Function定义
  10. dynamic 的使用 待续