当前位置:网站首页>Yyds dry goods inventory override and virtual of classes in C
Yyds dry goods inventory override and virtual of classes in C
2022-07-04 01:49:00 【Andy ahui】
Welcome to be my reader , I hope this article can give you some help .
Preface
I learned class derivation with you yesterday , Know the difference between derived class and base class .
Today, let's look at how the virtual methods and override methods of derived classes and base classes are used .
When we use base class references to access derived class objects , You get members of the base class . When using virtual methods , You can get the members and functions of the derived class .
The above code is a simple expression of base and derived classes , We try to pass the base class InfoBase To access derived classes Ahui The methods inside are shown in the output above .
From the above picture, you can see the access to... Through their respective instances GetInfo() Method returns different values , The base class returns its own , The derived class returns its own .
So when we want to use the reference of the base class to access the derived class object , Virtual methods can be used to access .
It must meet the following conditions :
- The method of the derived class and the method of the base class have the same signature and return type .
- The methods of the base class use virtual mark .
- Methods of derived classes use override mark .
Compare with the last output picture , You can see that when using virtual methods and overriding tags , All the output are members of derived classes .
It should be noted that :
- Overridden and overridden methods must have the same accessibility .
- Cannot override static Method or non virtual method .
- Method 、 Properties and indexers 、 Member type events can be declared as virtual and override.
remarks
Life is short , I don't want to pursue what I can't see , I just want to catch what I can see .
Originality is not easy. , Pay attention .
I am a A Hui , Thank you for reading , If it helps you , Please like it 、 forward thank you .
I'm glad to be friends with you .
边栏推荐
- Conditional test, if, case conditional test statements of shell script
- 2022 new examination questions for safety management personnel of hazardous chemical business units and certificate examination for safety management personnel of hazardous chemical business units
- Gee: create a new feature and set corresponding attributes
- What is the student party's Bluetooth headset recommendation? Student party easy to use Bluetooth headset recommended
- 2022 electrician (elementary) examination question bank and electrician (elementary) simulation examination question bank
- Ceramic metal crowns - current market situation and future development trend
- Audio resource settings for U3D resource management
- Force buckle day32
- Typescript basic knowledge sorting
- Life cycle of instance variables, static variables and local variables
猜你喜欢
MySQL - use of aggregate functions and group by groups
Life cycle of instance variables, static variables and local variables
51 MCU external interrupt
Three layer switching ②
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
Openbionics exoskeleton project introduction | bciduino community finishing
Maximum likelihood method, likelihood function and log likelihood function
Avoid playing with super high conversion rate in material minefields
Remember a lazy query error
A fan summed up so many interview questions for you. There is always one you need!
随机推荐
Maximum likelihood method, likelihood function and log likelihood function
How programmers find girlfriends through blind dates
Future source code view -juc series
Do you know the eight signs of a team becoming agile?
【.NET+MQTT】. Net6 environment to achieve mqtt communication, as well as bilateral message subscription and publishing code demonstration of server and client
Infiltration learning diary day19
0 basic learning C language - nixie tube dynamic scanning display
Jerry's update contact [article]
Jerry's modification setting status [chapter]
Some other configurations on Huawei's spanning tree
The automatic control system of pump station has powerful functions and diverse application scenarios
The difference between lambda expressions and anonymous inner classes
Feign implements dynamic URL
Force buckle day32
Maximum entropy model
Which insurance products can the elderly buy?
Huawei BFD and NQA
Solution of cursor thickening
C import Xls data method summary III (processing data in datatable)
Example 073 square sum value judgment programming requires the input of a and B, if a ²+ b ² If the result of is greater than 100, a is output ²+ b ² Value, otherwise output the result of a + B.