当前位置:网站首页>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
边栏推荐
- 百亿按摩仪蓝海,难出巨头
- OSI 七层模型
- Summary of the third class
- 做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史
- Go learning ----- relevant knowledge of JWT
- Nine hours, nine people, nine doors problem solving Report
- Fr exercise topic --- comprehensive question
- Temporary cramming before DFS examination
- Xiao Sha's arithmetic problem solving Report
- OSI seven layer model
猜你喜欢

First PR notes

Garbage collection mechanism of PHP (theoretical questions of PHP interview)

Good article inventory

Lesson 4 knowledge summary

华为哈勃化身硬科技IPO收割机

Ctfshow web entry explosion

OSI 七层模型

市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生

Common PHP interview questions (1) (written PHP interview questions)

F. Min cost string problem solving Report
随机推荐
Super wow fast row, you are worth learning!
What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?
Live broadcast preview | how to implement Devops with automatic tools (welfare at the end of the article)
Calculate weight and comprehensive score by R entropy weight method
1330:【例8.3】最少步数
Bugku's Ping
Reasons and solutions for redis cache penetration and cache avalanche
MySQL之CRUD
Summary of the second lesson
sql server学习笔记
"Sequelae" of the withdrawal of community group purchase from the city
Leetcode: Shortest Word Distance II
Crud de MySQL
Ecotone technology has passed ISO27001 and iso21434 safety management system certification
JMeter performance test: serveragent resource monitoring
P6183 [USACO10MAR] The Rock Game S
What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
Leetcode: Shortest Word Distance II
lv_font_conv离线转换
CODING DevSecOps 助力金融企业跑出数字加速度