当前位置:网站首页>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){
}
};
边栏推荐
- 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
- Use Scrollview and tabhost to realize vertical scrollbars and tabs
- 好用的 JS 脚本
- 剑指 Offer 30. 包含min函数的栈
- Audio and video engineer YUV and RGB detailed explanation
- HDU_ p1237_ Simple calculator_ stack
- Publish your own toolkit notes using NPM
- 500 lines of code to understand the principle of mecached cache client driver
- ftp上传文件时出现 550 Permission denied,不是用户权限问题
- Gbase 8C database upgrade error
猜你喜欢
零基础自学STM32-复习篇2——使用结构体封装GPIO寄存器
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
【社区人物志】专访马龙伟:轮子不好用,那就自己造!
【无标题】数据库中一条查询SQL执行的过程
RDD conversion operator of spark
[community personas] exclusive interview with Ma Longwei: the wheel is not easy to use, so make it yourself!
Campus second-hand transaction based on wechat applet
论文笔记: 图神经网络 GAT
Initial understanding of pointer variables
Computer graduation design PHP part-time recruitment management system for College Students
随机推荐
[robot library] awesome robots Libraries
MySQL learning notes - subquery exercise
Pangolin Library: subgraph
Overview of spark RDD
Using SA token to solve websocket handshake authentication
Structural theme model (I) STM package workflow
vs code保存时 出现两次格式化
The intelligent material transmission system of the 6th National Games of the Blue Bridge Cup
genius-storage使用文档,一个浏览器缓存工具
Zero foundation self-study STM32 - Review 2 - encapsulating GPIO registers with structures
[Clickhouse] Clickhouse based massive data interactive OLAP analysis scenario practice
Sword finger offer 30 Stack containing min function
This time, thoroughly understand the deep copy
使用npm发布自己开发的工具包笔记
[solution] every time idea starts, it will build project
Ue4- how to make a simple TPS role (II) - realize the basic movement of the role
Online reservation system of sports venues based on PHP
LeetCode 103. Binary tree zigzag level order transverse - Binary Tree Series Question 5
Computer graduation design PHP college student human resources job recruitment network
Global and Chinese markets of nasal oxygen tubes 2022-2028: Research Report on technology, participants, trends, market size and share