当前位置:网站首页>继承的构造函数
继承的构造函数
2022-07-06 02:17:00 【_Jxyz】
继承的构造函数
继承的构造函数不能初始化派生类的成员,可以使用类内初始化,或则追加构造函数
- using声明语句只是令某个名字在当前作用域内可见。而当作用于构造函数的时候,会产生代码。
using Base::Base;
- 对于基类的每个构造函数,编译器都生成一个与之对应的派生类构造函数
- 不会改变构造函数的控制权限,比如说基类中的构造函数时private,继承在派生类中的也是private
- 由于using只能指定名字,所以基类中构造函数如果存在explicit 和 constexpr关键及同样会被继承。
- 如果一个基类的构造函数含有默认实参,将会生成多个构造函数,其中每个构造函数分别省略掉一个含有默认实参的形参。比如基类有一个两个参数的构造函数,第二个参数为默认实参,则会参数一个两个参数的构造函数(都不是默认实参)和一个参数(第一个参数)的构造函数
- 默认、拷贝、移动构造函数不会被继承, 这些构造函数按照正常的规则被合成
C++11 标准规定,继承构造函数与类的一些默认函数(默认构造、析构、拷贝构造函数等)一样,是隐式声明,如果一个继承构造函数不被相关代码使用,编译器不会为其产生真正的函数代码。这样比通过派生类构造函数“透传构造函数参数”来完成基类初始化的方式,总是需要定义派生类的各种构造函数更加节省目标代码空间。
多继承的情况下,
继承构造函数会出现“冲突”的情况,因为多个基类中的部分构造函数可能导致派生类中的继承构造函数的函数名与参数相同
class A {
public:
A(int i){
}
};
class B {
public:
B(int i){
}
};
class C : public A, public B {
public:
// using A::A; //编译出错,重复定义C(int)
// using B::B; //编译出错,重复定义C(int)
// 显示定义继承构造函数 C(int)
C(int i):A(i),B(i){
}
};
边栏推荐
- It's wrong to install PHP zbarcode extension. I don't know if any God can help me solve it. 7.3 for PHP environment
- 01. Go language introduction
- 【MySQL 15】Could not increase number of max_open_files to more than 10000 (request: 65535)
- Genius storage uses documents, a browser caching tool
- Keyword static
- Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
- Lecture 4 of Data Engineering Series: sample engineering of data centric AI
- SSM assembly
- Use image components to slide through photo albums and mobile phone photo album pages
- 论文笔记: 极限多标签学习 GalaXC (暂存, 还没学完)
猜你喜欢

剑指 Offer 29. 顺时针打印矩阵

Keyword static

Lecture 4 of Data Engineering Series: sample engineering of data centric AI

SPI communication protocol

RDD conversion operator of spark

How does redis implement multiple zones?

同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样

3D drawing ()

安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3

vs code保存时 出现两次格式化
随机推荐
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
Audio and video engineer YUV and RGB detailed explanation
Redis string type
02. Go language development environment configuration
It's wrong to install PHP zbarcode extension. I don't know if any God can help me solve it. 7.3 for PHP environment
Leetcode sum of two numbers
Gbase 8C database upgrade error
Ali test open-ended questions
Competition question 2022-6-26
Virtual machine network, networking settings, interconnection with host computer, network configuration
How to improve the level of pinduoduo store? Dianyingtong came to tell you
2022 eye health exhibition, vision rehabilitation exhibition, optometry equipment exhibition, eye care products exhibition, eye mask Exhibition
729. My schedule I / offer II 106 Bipartite graph
This time, thoroughly understand the deep copy
Overview of spark RDD
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
Unity learning notes -- 2D one-way platform production method
Compact lidar global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
Computer graduation design PHP campus restaurant online ordering system
【coppeliasim】6自由度路径规划