virtual function and pure virtual function __ function

Source: Internet
Author: User

1. Virtual functions and pure virtual functions can be defined in the same class (class), classes containing pure virtual functions are called abstract classes (abstract class), and classes that contain only virtual functions cannot be called abstract classes.

2. A virtual function can be used directly, or it can be invoked in polymorphic form after a quilt class (sub Class) overload, whereas a pure virtual function must be implemented in a subclass (sub Class) to be used, because pure virtual functions are in the base class (base classes)
Only declarations are not defined.

3. Both virtual functions and pure virtual functions can be overloaded in subclasses (sub Class) and invoked in polymorphic form.

4. Virtual functions and pure virtual functions often exist in abstract base classes (abstract base class-abc), inherited subclass overloads, to provide a unified interface.

5. Definition form of virtual function: virtual {method Body}
The definition form of pure virtual function: virtual {} = 0;
There cannot be a static identifier in the definition of a virtual function and a pure virtual function, for the simple reason that a function that is modified by static requires bind at compile time, whereas a virtual function is dynamically bound (run-time bind) and is decorated with a function lifecycle (life Recycle) is not the same.

6. If a class contains a pure virtual function, any statement that attempts to instantiate the class will cause the error to occur because the abstract base class (ABC) cannot be invoked directly. A method that calls its subclasses after a quilt class inherits the overload.

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.