当前位置:网站首页>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){
}
};
边栏推荐
- Exness: Mercedes Benz's profits exceed expectations, and it is predicted that there will be a supply chain shortage in 2022
- Initial understanding of pointer variables
- VIM usage guide
- Building the prototype of library functions -- refer to the manual of wildfire
- Paper notes: graph neural network gat
- Global and Chinese market of commercial cheese crushers 2022-2028: Research Report on technology, participants, trends, market size and share
- 3D drawing ()
- Computer graduation design PHP enterprise staff training management system
- Advanced technology management - what is the physical, mental and mental strength of managers
- Ue4- how to make a simple TPS role (II) - realize the basic movement of the role
猜你喜欢

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

2022年版图解网络PDF

【MySQL 15】Could not increase number of max_open_files to more than 10000 (request: 65535)

Computer graduation design PHP enterprise staff training management system

Sword finger offer 30 Stack containing min function

零基础自学STM32-野火——GPIO复习篇——使用绝对地址操作GPIO

Concept of storage engine

Using SA token to solve websocket handshake authentication

Blue Bridge Cup embedded_ STM32 learning_ Key_ Explain in detail

SQL statement
随机推荐
Multi function event recorder of the 5th National Games of the Blue Bridge Cup
[coppeliasim] efficient conveyor belt
技术管理进阶——什么是管理者之体力、脑力、心力
【无标题】数据库中一条查询SQL执行的过程
Audio and video engineer YUV and RGB detailed explanation
Overview of spark RDD
[robot library] awesome robots Libraries
从顶会论文看2022年推荐系统序列建模的趋势
Spark accumulator
MySQL (IV) - transactions
【clickhouse】ClickHouse Practice in EOI
SQL statement
[coppeliasim] 6-DOF path planning
模板_快速排序_双指针
Computer graduation design PHP campus restaurant online ordering system
Multiple solutions to one problem, asp Net core application startup initialization n schemes [Part 1]
Social networking website for college students based on computer graduation design PHP
怎么检查GBase 8c数据库中的锁信息?
0211 embedded C language learning
Use the list component to realize the drop-down list and address list