当前位置:网站首页>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){
}
};
边栏推荐
- Computer graduation design PHP enterprise staff training management system
- PHP campus movie website system for computer graduation design
- How to set an alias inside a bash shell script so that is it visible from the outside?
- Spark accumulator
- MySQL learning notes - subquery exercise
- Global and Chinese markets of screw rotor pumps 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets hitting traffic doors 2022-2028: Research Report on technology, participants, trends, market size and share
- 同一个 SqlSession 中执行两条一模一样的SQL语句查询得到的 total 数量不一样
- [untitled] a query SQL execution process in the database
- 0211 embedded C language learning
猜你喜欢
【社区人物志】专访马龙伟:轮子不好用,那就自己造!
好用的 JS 脚本
安装php-zbarcode扩展时报错,不知道有没有哪位大神帮我解决一下呀 php 环境用的7.3
[Wu Enda machine learning] week5 programming assignment EX4 - neural network learning
Minecraft 1.18.1、1.18.2模组开发 22.狙击枪(Sniper Rifle)
Advanced technology management - what is the physical, mental and mental strength of managers
从顶会论文看2022年推荐系统序列建模的趋势
Building the prototype of library functions -- refer to the manual of wildfire
[width first search] Ji Suan Ke: Suan tou Jun goes home (BFS with conditions)
2022 China eye Expo, Shandong vision prevention and control exhibition, myopia, China myopia correction Exhibition
随机推荐
Minecraft 1.18.1, 1.18.2 module development 22 Sniper rifle
Concept of storage engine
The third level of C language punch in
MySQL index
RDD creation method of spark
Use the list component to realize the drop-down list and address list
HttpRunnerManager安装(三)-Linux下配置myql数据库&初始化数据
Audio and video engineer YUV and RGB detailed explanation
How does redis implement multiple zones?
2022 edition illustrated network pdf
Easy to use js script
Genius storage uses documents, a browser caching tool
729. 我的日程安排表 I / 剑指 Offer II 106. 二分图
MySQL (IV) - transactions
技术管理进阶——什么是管理者之体力、脑力、心力
Visualstudio2019 compilation configuration lastools-v2.0.0 under win10 system
构建库函数的雏形——参照野火的手册
There are so many giants, why should we independently develop POS store cashier system?
Minecraft 1.16.5 生化8 模组 2.0版本 故事书+更多枪械
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]