当前位置:网站首页>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
边栏推荐
猜你喜欢
Crud de MySQL
P1451 求细胞数量/1329:【例8.2】细胞
Your childhood happiness was contracted by it
Common redis data types and application scenarios
Appium自动化测试基础 — APPium基础操作API(二)
Redis' transaction mechanism
市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
"Sequelae" of the withdrawal of community group purchase from the city
Explanation report of the explosion
Ten billion massage machine blue ocean, difficult to be a giant
随机推荐
Transfer the idea of "Zhongtai" to the code
MySQL表字段调整
Calculate weight and comprehensive score by R entropy weight method
Summary of the third class
Bugku's Ah Da
How can the boss choose programmers to help me with development?
当代人的水焦虑:好水究竟在哪里?
市值蒸发超百亿美元,“全球IoT云平台第一股”赴港求生
Explanation report of the explosion
Summary of the second lesson
Temporary cramming before DFS examination
ionic cordova项目修改插件
Appium自动化测试基础 — APPium基础操作API(二)
Huawei Hubble incarnation hard technology IPO harvester
queryRunner. Query method
Ctfshow web entry command execution
复现Thinkphp 2.x 任意代码执行漏洞
Xiao Sha's arithmetic problem solving Report
百亿按摩仪蓝海,难出巨头
DVWA range clearance tutorial