当前位置:网站首页>继承的构造函数
继承的构造函数
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){
}
};
边栏推荐
- MySQL lethal serial question 1 -- are you familiar with MySQL transactions?
- Leetcode3. Implement strstr()
- 【clickhouse】ClickHouse Practice in EOI
- 模板_快速排序_双指针
- Selenium element positioning (2)
- 3D drawing ()
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- leetcode3、實現 strStr()
- SQL statement
- I like Takeshi Kitano's words very much: although it's hard, I will still choose that kind of hot life
猜你喜欢
【社区人物志】专访马龙伟:轮子不好用,那就自己造!
Selenium waiting mode
Overview of spark RDD
How does redis implement multiple zones?
[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!
Unity learning notes -- 2D one-way platform production method
2022 PMP project management examination agile knowledge points (8)
2022 eye health exhibition, vision rehabilitation exhibition, optometry equipment exhibition, eye care products exhibition, eye mask Exhibition
How to improve the level of pinduoduo store? Dianyingtong came to tell you
Computer graduation design PHP animation information website
随机推荐
Derivation of Biot Savart law in College Physics
Paper notes: limit multi label learning galaxc (temporarily stored, not finished)
【coppeliasim】6自由度路径规划
Leetcode sum of two numbers
爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
Executing two identical SQL statements in the same sqlsession will result in different total numbers
Number conclusion LC skimming review - 1
Pangolin Library: subgraph
【机器人手眼标定】eye in hand
Using SA token to solve websocket handshake authentication
2022 eye health exhibition, vision rehabilitation exhibition, optometry equipment exhibition, eye care products exhibition, eye mask Exhibition
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Initial understanding of pointer variables
Jisuanke - t2063_ Missile interception
Overview of spark RDD
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
02. Go language development environment configuration
从顶会论文看2022年推荐系统序列建模的趋势
729. 我的日程安排表 I / 剑指 Offer II 106. 二分图
How to improve the level of pinduoduo store? Dianyingtong came to tell you