C++学习笔记:继承中的构造与析构
来源:互联网 发布:四川广电网络成都 编辑:程序博客网 时间:2024/06/05 07:19
子类是由父类成员叠加子类新成员得到的。
继承中的构造析构函数调用原则
1.子类对象在创建时会首先调用父类的构造函数
2.父类构造函数执行结束后,执行子类的构造函数
3.当父类的构造函数有参数时,需要再子类的初始化列表中显式调用
4.析构函数调用的先后吮吸与构造函数相反
// 继承中构造和析构.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include<iostream>using namespace std;class Parent{public:Parent(int a,int b){this->a = a;this->b = b;cout << "调用父类构造函数" << endl;}~Parent(){cout << "调用父类析构函数" << endl;}protected:private:int a;int b;};class Child :public Parent{public:Child(int a,int b,int c) :Parent(a,b){this->c = c;cout << "调用子类构造函数" << endl;}~Child(){cout << "调用子类析构函数" << endl;}protected:private:int c;};void playObj(){Child c1(1,2,3);}int _tmain(int argc, _TCHAR* argv[]){playObj();return 0;}
0 0
- C++学习笔记18 继承中的构造与析构
- C++学习笔记:继承中的构造与析构
- C++学习笔记--继承中的构造与析构
- c++学习笔记(11.继承的构造与析构)
- dephi继承中的构造与析构
- 继承中的构造与析构
- 【十三】继承中的构造与析构
- c++继承中的构造与析构
- 46-继承中的构造与析构
- [C++]继承与构造析构
- Java学习笔记--继承中的构造方法
- 【C++】【学习笔记】【017】继承机制中的构造器和析构器
- C++学习笔记_2:单一继承时的构造函数与析构函数
- GeekBand C++学习笔记——继承、复合当中的构造与析构
- 继承中的构造和析构、继承与组合混搭下的构造和析构
- python学习笔记——旧类与新类继承中的构造函数
- C++学习笔记49——继承中的复制构造函数与赋值操作符
- (多)继承中的构造与析构
- oracle 创建用户并且分配权限
- 【bzoj1355】[Baltic2009]Radio Transmission KMP
- C# 连接 mysql数据库
- 【JavaScript学习笔记】基本知识点
- 使用gitolite搭建代码库
- C++学习笔记:继承中的构造与析构
- 博弈论
- PL/SQL Developer中汉字显示乱码问题
- spring scheduler 定时器
- iOS小明开发笔记(二十七) (Autolayout(VFL)一)
- 启动eclipse报Version 1.6.0_65 of the JVM is not suitable for this product.
- Javascript的正则表达式
- copy命令中路径不要使用/
- 用eclipse创建java web工程 (最详细的讲解)