当前位置:网站首页>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
边栏推荐
猜你喜欢

Common MySQL interview questions

Your childhood happiness was contracted by it

I spring and autumn blasting-2

No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle

lvgl 显示图片示例

MySQL 巨坑:update 更新慎用影响行数做判断!!!

Crud de MySQL

Transfer the idea of "Zhongtai" to the code

Bugku alert

Object. defineProperty() - VS - new Proxy()
随机推荐
Huawei Hubble incarnation hard technology IPO harvester
How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
Brief introduction of machine learning framework
What are the domestic formal futures company platforms in 2022? How about founder metaphase? Is it safe and reliable?
Misc Basic test method and knowledge points of CTF
String modification problem solving Report
swiper. JS to achieve barrage effect
百亿按摩仪蓝海,难出巨头
Anaconda uses China University of science and technology source
I include of spring and Autumn
Ecotone technology has passed ISO27001 and iso21434 safety management system certification
Fr exercise topic --- comprehensive question
Xiao Sha's arithmetic problem solving Report
一文搞定vscode编写go程序
Explanation report of the explosion
Definition of episodic and batch
Object. defineProperty() - VS - new Proxy()
Severlet learning foundation
The elimination strategy of redis
漫画:程序员不是修电脑的!