当前位置:网站首页>inherited constructors
inherited constructors
2022-07-06 02:24:00 【_ Jxyz】
Inherited constructors
Inherited constructors cannot initialize members of derived classes , You can use class initialization , Or append constructor
- using A declaration statement simply makes a name visible in the current scope . When used as a constructor , Will generate code .
using Base::Base;
- For each constructor of the base class , Compilers generate a corresponding derived class constructor
- The control permission of constructor will not be changed , For example, when the constructor in the base class private, Inheritance in derived classes is also private
- because using Only name can be specified , So if the constructor in the base class exists explicit and constexpr The key and will also be inherited .
- If the constructor of a base class contains default arguments , Multiple constructors will be generated , Each constructor omits a formal parameter with a default argument . For example, the base class has a constructor with two parameters , The second parameter is the default argument , Then a constructor with two parameters ( Are not default arguments ) And a parameter ( The first parameter ) Constructor for
- Default 、 Copy 、 The move constructor is not inherited , These constructors are synthesized according to normal rules
C++11 The standard stipulates , Inherit constructors and some default functions of classes ( Default structure 、 destructor 、 Copy constructors, etc ) equally , Is an implicit declaration , If an inheritance constructor is not used by related code , The compiler doesn't generate real function code for it . This is better than using derived class constructors “ Pass through constructor parameters ” To complete the initialization of the base class , You always need to define various constructors of derived classes to save more object code space .
In the case of multiple inheritance ,
The inheritance constructor will appear “ Conflict ” The situation of , Because some constructors in multiple base classes may cause the function name of the inherited constructor in the derived class to be the same as the parameter
class A {
public:
A(int i){
}
};
class B {
public:
B(int i){
}
};
class C : public A, public B {
public:
// using A::A; // Compilation error , Repeat the definition C(int)
// using B::B; // Compilation error , Repeat the definition C(int)
// Display definition inheritance constructor C(int)
C(int i):A(i),B(i){
}
};
边栏推荐
- 更换gcc版本后,编译出现make[1]: cc: Command not found
- 2022 edition illustrated network pdf
- Sword finger offer 29 Print matrix clockwise
- 剑指 Offer 29. 顺时针打印矩阵
- 好用的 JS 脚本
- PAT甲级 1033 To Fill or Not to Fill
- How to generate rich text online
- Global and Chinese markets for single beam side scan sonar 2022-2028: Research Report on technology, participants, trends, market size and share
- [solution] add multiple directories in different parts of the same word document
- Use the list component to realize the drop-down list and address list
猜你喜欢

Campus second-hand transaction based on wechat applet

500 lines of code to understand the principle of mecached cache client driver
![[robot library] awesome robots Libraries](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[robot library] awesome robots Libraries

从顶会论文看2022年推荐系统序列建模的趋势

LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5

vs code保存时 出现两次格式化

Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022

Zero basic self-study STM32 wildfire review of GPIO use absolute address to operate GPIO

Blue Bridge Cup embedded_ STM32_ New project file_ Explain in detail

Overview of spark RDD
随机推荐
HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
事故指标统计
729. 我的日程安排表 I / 剑指 Offer II 106. 二分图
A basic lintcode MySQL database problem
一题多解,ASP.NET Core应用启动初始化的N种方案[上篇]
Method of changing object properties
怎么检查GBase 8c数据库中的锁信息?
2022 edition illustrated network pdf
Use image components to slide through photo albums and mobile phone photo album pages
同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
Computer graduation design PHP part-time recruitment management system for College Students
Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle
Jisuanke - t2063_ Missile interception
Computer graduation design PHP animation information website
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
Multi function event recorder of the 5th National Games of the Blue Bridge Cup
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
好用的 JS 脚本
[solution] every time idea starts, it will build project
更改对象属性的方法