C++ subclass overrides base class and virtual processing

Publisher:Bby1978Latest update time:2015-05-08 Source: 51heiKeywords:C++ Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include
class animal
{
public:
animal()
{
cout<<"animal construct"<
}
~animal()
{
cout<<"construct animal"<
}
virtual void breath() //virtual defines virtual function
{
cout<<"bubble2"<
}
};
class fish:public animal //Only call animal() in animal
{
public:
fish()
{
// cout<<"hello world"<
}
~fish()
{
// cout<<"construct helllo world"<
}
 void breath()
{   
//animal::breath();
//cout<<"fish bubble"<
}
};
void fn(animal *pan)
{
pan->breath();
}
void main()
{
fish fh;
//st.breath ();//If the subclass and the base class have two functions with the same name , the subclass will eventually overwrite the base class, which is called overloading.
animal *pan;
pan=&fh; //Change the pointer and replace the pointer of animal with fish. But it still outputs animal. If virtual is added before animal, it will output fish
fn(pan);
}

Keywords:C++ Reference address:C++ subclass overrides base class and virtual processing

Previous article:Serial communication between microcontroller and host computer
Next article:How to create header files in C++

Recommended ReadingLatest update time:2024-11-16 20:30

Research on the setting and application of 80C51 reset flag bit
introduction   Setting the reset flag bit is convenient for distinguishing resets caused by different reasons. As a new technology, it is adopted by more and more new microcontrollers. For example, the P87LPC700 and P89LPC900 series of Philips Company, the MC68HC05 series and MC68HC08 series of Freescale Company (fo
[Microcontroller]
ROHM's BD8758xYx-C operational amplifier achieves outstanding performance in four types of noise immunity tests
ROHM develops operational amplifier "BD8758xYx-C" that achieves excellent performance in four types of noise immunity tests The EMARMOUR™ Series has the strongest anti-interference performance, which helps reduce the design time of abnormality detection systems and improve reliability ROH
[Analog Electronics]
ROHM's BD8758xYx-C operational amplifier achieves outstanding performance in four types of noise immunity tests
PT100 temperature detection system based on AT89C51 microcontroller
1. System Overview The modules used in the system include AT89C51 microcontroller + 8-bit common cathode digital tube + ADC0804 analog-to-digital conversion + PT100 temperature detection. The system uses AT89C51 microcontroller as the main control, and uses PT100 to detect the temperature. The detected temperature a
[Microcontroller]
PT100 temperature detection system based on AT89C51 microcontroller
Design of network coordinator based on CC2420 radio frequency chip and S3C2440 chip
1 Overview There are various wireless communication methods. Compared with Bluetooth, Wi-Fi, and GSM mobile communication methods, the ZigBee method developed by the ZigBee Alliance has the advantages of low power consumption, reliable data transmission, good compatibility, low implementation cost, and convenient netw
[Microcontroller]
Design of network coordinator based on CC2420 radio frequency chip and S3C2440 chip
Suspected iPhone 12 USB-C to Lightning braided cable exposed again
Rumor has it that Apple's upcoming iPhone 12 models will come with a new USB-C to Lightning cable, and the biggest feature of this new charging cable is its braided fabric design. Today, Twitter whistleblower @Mr White shared new pictures. The photo clearly shows that the new charging cable has a braided design, rat
[Mobile phone portable]
C language programming of 8051 microcontroller
      8051 C programming is similar to traditional C programming. Of course, some data types are different. As we know, 8051 supports powerful bit addressing capabilities, so 8051 C programming adds some new data types to avoid wasting the capabilities of 8051. The following are the newly added data types.        bi
[Microcontroller]
C language programming of 8051 microcontroller
pic12C508 ultrasonic rangefinder program
; Ultrasonic rangefinder   ; Internal Osc, WDT Enab LED       include p12c508.inc   loop equ 10h      dly CTR         equ 11h          tone_cnt equ 12h ; reflection period count  period equ 13h ; tmr0 overflow time      org 0                 MOVwf OS CC AL              MOVlw b'10001001'              option ;1:2 WDT
[Microcontroller]
Design of Gas Leakage Alarm Based on AT89C51
0 Introduction With the popularization of urban pipeline and bottled gas, gas leakage, explosion or poisoning accidents caused by improper use and aging equipment occur from time to time, so the installation of gas alarms has received more and more attention. However, the development of gas alarms is very unbalance
[Microcontroller]
Design of Gas Leakage Alarm Based on AT89C51
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号