------virtual function of C + +

Source: Internet
Author: User

C + + virtual functions

In Smartos, the key word for virtual is the virtual function definition of C + +

The member function, which is modified by the keyword of virtual, is the virtual function

Virtual functions are redefined by the program when they are inherited, and when used, they are inherited by the same base class (parent Class) lock, their function names are the same, but their functions are different, and that is his polymorphism.

The polymorphism in object-oriented programming is to send the same message to different objects, and different objects produce different behaviors for the same message. In the program, the message is called the function, the different behavior refers to the different implementation method, namely executes the different function body. It can also be said that the implementation of "one interface, a variety of methods."

1 protected:2Gpio_inittypedef Gpio;//struct-Body object for configuring ports3 4 Port ();5     Virtual~Port ();6 7     voidSetport (PIN pin);//Single PIN initialization8     voidSetport (Pin pins[],UINTcount);//initialized with a set of pins, the PIN group Gpiox is determined by the first pin, make sure all pins are in the same group Gpiox9     voidSetport (gpio_typedef* Group,ushortPinbit =gpio_pin_all);Ten  One     //configuration process, called by Config, and finally Gpio_init A     Virtual voidOnConfig ();

------virtual function of C + +

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.