当前位置:网站首页>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
边栏推荐
- Hongmeng system -- Analysis from the perspective of business
- Can gbase 8A view the location of SQL statement history?
- What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
- go语言编程规范梳理总结
- Brief introduction of machine learning framework
- D-snow halo solution
- Ten billion massage machine blue ocean, difficult to be a giant
- ICML 2022 | explore the best architecture and training method of language model
- Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
- [recruitment position] infrastructure software developer
猜你喜欢
随机推荐
String modification problem solving Report
Anti shake and throttling
Redis distributed lock principle and its implementation with PHP (1)
Database learning - Database Security
Common PHP interview questions (1) (written PHP interview questions)
What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
Usage and usage instructions of JDBC connection pool
Bugku's steganography
Misc Basic test method and knowledge points of CTF
sql server学习笔记
Hongmeng system -- Analysis from the perspective of business
[brief notes] solve the problem of IDE golang code red and error reporting
Reasons and solutions for redis cache penetration and cache avalanche
queryRunner. Query method
Cartoon: programmers don't repair computers!
Thymeleaf uses background custom tool classes to process text
Where is the operation of convertible bond renewal? Is it safer and more reliable to open an account
"Sequelae" of the withdrawal of community group purchase from the city
【简记】解决IDE golang 代码飘红报错
Bugku's eyes are not real
![[JVM] operation instruction](/img/f5/85580495474ef58eafbb421338e93f.png)








