对于派生类的构造函数,创建对象时构造函数执行的顺序

1)基类的构造函数。

2)成员对象构造函数。

3)派生类本身的构造函数。

记忆方式:先父母,再客人,后自己。

cpp 复制代码
#include <iostream>
#include <thread>
#include <string>
#include <iostream>
using namespace std;

class AAA {
public:
	AAA() { cout<<"AAA"<<endl;}
	~AAA(){} 
};
class CCC {
public:
	CCC() { cout<<"CCC"<<endl;}
	~CCC() {}
};

class BBB :public AAA{
public:
	BBB() { cout<<"BBB"<<endl;}
	~BBB() {}
private:
	CCC c;
};

int main()						
{
	BBB *b = new BBB;
	delete b;

	return 0;
}
相关推荐
雪度娃娃1 天前
C++异步日志系统
开发语言·c++
kyle~1 天前
ROS2---路径机制辨析
c++·机器人·ros2
charlie1145141911 天前
基于开源项目的现代C++工程实践——OnceCallback 前置知识(下):C++20/23 高级特性
c++·开源·c++20
蜡笔小马1 天前
04.C++设计模式-桥接模式
c++·设计模式·桥接模式
宏笋1 天前
C++ using typedef #define 三者的优缺点比较
c++
枕星而眠1 天前
一篇吃透 C++ 核心基础:初始化、引用、指针、内联、重载、右值引用
开发语言·数据结构·c++·后端·visual studio
小明同学011 天前
计算机网络编程---系统调用到并发模型
linux·c++·计算机网络
Season4501 天前
C/C++的类型转换
c语言·开发语言·c++
Titan20241 天前
C++特殊类设计
c++·学习
明日清晨1 天前
有符号与无符号数转换
c++