当前位置:网站首页>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 .
边栏推荐
- Applet graduation project based on wechat selection voting applet graduation project opening report function reference
- MySQL deadly serial question 2 -- are you familiar with MySQL index?
- In yolov5, denselayer is used to replace focus, and the FPN structure is changed to bi FPN
- Portable two-way radio equipment - current market situation and future development trend
- 51 single chip microcomputer timer 2 is used as serial port
- Special copy UML notes
- Containerization technology stack
- Lightweight Pyramid Networks for Image Deraining
- Setting function of Jerry's watch management device [chapter]
- The automatic control system of pump station has powerful functions and diverse application scenarios
猜你喜欢

Gee: create a new feature and set corresponding attributes

Make drop-down menu

Solution to the problem that jsp language cannot be recognized in idea

SQL statement
![Setting function of Jerry's watch management device [chapter]](/img/0b/8fab078e1046dbc22aa3327c49faa7.jpg)
Setting function of Jerry's watch management device [chapter]

Feign implements dynamic URL
![Jerry's watch listens to the message notification of the target third-party software and pushes the message to the device [article]](/img/8b/ff062f34d36e1caa9909c8ab431daf.jpg)
Jerry's watch listens to the message notification of the target third-party software and pushes the message to the device [article]
![After listening to the system clear message notification, Jerry informed the device side to delete the message [article]](/img/0c/52816b75eb702c7c63966578ab4969.jpg)
After listening to the system clear message notification, Jerry informed the device side to delete the message [article]

Should enterprises start building progressive web applications?

Infiltration learning diary day19
随机推荐
Feign implements dynamic URL
Conditional statements of shell programming
Conditional test, if, case conditional test statements of shell script
Luogu p1309 Swiss wheel
Related configuration commands of Huawei rip
Hunan University | robust Multi-Agent Reinforcement Learning in noisy environment
Difference between value and placeholder
A fan summed up so many interview questions for you. There is always one you need!
I don't know why it can't run in the project and how to change it
JVM performance tuning and practical basic theory - medium
Small program graduation design is based on wechat order takeout small program graduation design opening report function reference
Which insurance products can the elderly buy?
Chinese Mitten Crab - current market situation and future development trend
Software product download collection
C import Xls data method summary I (upload files and create Workbooks)
Idea if a class cannot be found, it will be red
Maximum likelihood method, likelihood function and log likelihood function
Solution to the problem that jsp language cannot be recognized in idea
Some other configurations on Huawei's spanning tree
Lightweight Pyramid Networks for Image Deraining