当前位置:网站首页>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
边栏推荐
- Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
- CSDN I'm coming
- Bugku's Eval
- Number protection AXB function! (essence)
- go语言编程规范梳理总结
- I spring web upload
- How can the boss choose programmers to help me with development?
- D-snow halo solution
- Ctfshow web entry explosion
- ICML 2022 | 探索语言模型的最佳架构和训练方法
猜你喜欢
keep-alive
超越PaLM!北大硕士提出DiVeRSe,全面刷新NLP推理排行榜
Bugku's Ping
Advanced level of static and extern
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
Object. defineProperty() - VS - new Proxy()
I spring and autumn blasting-2
Bubble sort, insert sort
CSRF, XSS science popularization and defense
Bugku's Eval
随机推荐
Go learning ----- relevant knowledge of JWT
What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
CSDN I'm coming
R 熵权法计算权重及综合得分
OSI 七层模型
Bugku's Eval
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
Hongmeng system -- Analysis from the perspective of business
Bubble sort, insert sort
DVWA range clearance tutorial
Creation and use of thymeleaf template
美团优选管理层变动:老将刘薇调岗,前阿里高管加盟
超越PaLM!北大碩士提出DiVeRSe,全面刷新NLP推理排行榜
可转债打新在哪里操作开户是更安全可靠的呢
MySQL5.7的JSON基本操作
String modification problem solving Report
JS knowledge points-01
go学习 ------jwt的相关知识
Where is the operation of convertible bond renewal? Is it safer and more reliable to open an account
Garbage collection mechanism of PHP (theoretical questions of PHP interview)