当前位置:网站首页>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
边栏推荐
猜你喜欢
Explanation report of the explosion
Huawei Hubble incarnation hard technology IPO harvester
Advanced level of static and extern
Good article inventory
Thymeleaf uses background custom tool classes to process text
百亿按摩仪蓝海,难出巨头
lv_font_conv离线转换
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
Bubble sort, insert sort
Crud of MySQL
随机推荐
数据库学习——数据库安全性
Usage and usage instructions of JDBC connection pool
Redis distributed lock principle and its implementation with PHP (2)
Fr exercise topic - simple question
美团优选管理层变动:老将刘薇调岗,前阿里高管加盟
JS topic - console log()
CODING DevSecOps 助力金融企业跑出数字加速度
Misc Basic test method and knowledge points of CTF
MySQL之CRUD
Optional parameters in the for loop
Temporary cramming before DFS examination
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
Array sorting num ranking merge in ascending order
Good article inventory
Common interview questions about swoole
Bugku cyberpunk
【簡記】解决IDE golang 代碼飄紅報錯
Go learning ----- relevant knowledge of JWT
The difference between abstract classes and interfaces in PHP (PHP interview theory question)
Au - delà du PARM! La maîtrise de l'Université de Pékin propose diverse pour actualiser complètement le classement du raisonnement du NLP