当前位置:网站首页>Virtual base class (a little difficult)
Virtual base class (a little difficult)
2022-07-05 15:34:00 【Xuanhong Zhou】
Solving ambiguity
Inherited a member with the same name from multiple base classes :
adopt
1. The class name is qualified
2. The same name is hidden
3.using sentence
To solve
Inherited multiple base classes , These multiple base classes have the same base class , At this time, use the virtual base class to solve
Go straight to the topic
1. The following description of virtual base classes , The wrong is ( ).
A、 Statement “class B : virtual public A” Description class B Is a virtual base class
B、 When creating a derived class object , The constructor of the virtual base class is called only once
C、 Using virtual base classes can eliminate the ambiguity caused by multiple inheritance
D、 When creating a derived class object , First, call the constructor of the virtual base class
Think so , because A Is a class that has been used many times , So set it to virtual , so A Option A Is a virtual base class
Carry the rest on your back
When creating an object , Only the constructor of the most derived class calls the constructor of the virtual base class , Calls from other classes to the virtual base class constructor are ignored
2. The ways to solve the ambiguity problem are ( ).
A、 Only scope operators can be used
B、 Use scope operators or assignment compatibility rules
C、 Use scope operators or virtual base classes
D、 Use virtual base classes or assignment compatibility rules
C
3. The construction order of multiple inheritance can be divided into the following 4 Step :
(1) Constructors of all non virtual base classes are constructed in the order they are inherited ;
(2) Constructors of all virtual base classes are constructed in the order they are inherited ;
(3) Constructors for all child objects are constructed in the order they are declared ;
(4) The constructor body of the derived class itself ;
this 4 The correct sequence of the steps is ( ).
A、(4)(3)(1)(2)
B、(2)(4)(3)(1)
C、(2)(1)(3)(4)
D、(3)(4)(1)(2)
C
First virtual base class , Then base class , Then sub objects , Then own members
4. What is wrong in the following statement is ( ).
A、 Derived classes can use private The derived
B、 Access to base class members must be unambiguous
C、 The access ability of base class members remains unchanged in derived classes
D、 Assignment compatibility rules also apply to multiple inheritance
C
This C Only public Inherit without changing access , The rest become corresponding
边栏推荐
- Redis distributed lock principle and its implementation with PHP (1)
- Dark horse programmer - software testing -10 stage 2-linux and database -44-57 why learn database, description of database classification relational database, description of Navicat operation data, de
- How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
- [recruitment position] Software Engineer (full stack) - public safety direction
- Good article inventory
- 数学建模之层次分析法(含MATLAB代码)
- Super wow fast row, you are worth learning!
- Number protection AXB function! (essence)
- qt creater断点调试程序详解
- 把 ”中台“ 的思想迁移到代码中去
猜你喜欢

Lesson 4 knowledge summary

基于OpenHarmony的智能金属探测器

Ionic Cordova project modification plug-in

Explanation report of the explosion

MySQL----函数

Detailed explanation of C language branch statements

30岁汇源,要换新主人了

Huiyuan, 30, is going to have a new owner

CODING DevSecOps 助力金融企业跑出数字加速度

Reasons and solutions for redis cache penetration and cache avalanche
随机推荐
P1451 calculate the number of cells / 1329: [example 8.2] cells
"Sequelae" of the withdrawal of community group purchase from the city
Summary of the third class
Calculate weight and comprehensive score by R entropy weight method
做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史
Severlet learning foundation
Ten billion massage machine blue ocean, difficult to be a giant
F. Min cost string problem solving Report
数学建模之层次分析法(含MATLAB代码)
JS knowledge points-01
CODING DevSecOps 助力金融企业跑出数字加速度
First PR notes
Ecotone technology has passed ISO27001 and iso21434 safety management system certification
JMeter performance test: serveragent resource monitoring
sql server char nchar varchar和nvarchar的区别
Common redis data types and application scenarios
Go learning ----- relevant knowledge of JWT
【 note 】 résoudre l'erreur de code IDE golang
Common PHP interview questions (1) (written PHP interview questions)
亿咖通科技通过ISO27001与ISO21434安全管理体系认证