Comparison between virtual functions and pure virtual functions (continuous learning and updating)

Source: Internet
Author: User

Virtual Functions

Class member functions declared using the virtual keyword. It can be implemented at the time of declaration or outside the class declaration.

Class C1 {<br/> virtual void a (); <br/> virtual int B () {}< br/> };

 

Pure virtual functions

Declare using the virtual keyword and class member functions with = 0 after the prototype declaration. Function implementation is not allowed in the function prototype. However, in the function external body, pure virtual functions can be implemented.

Classes containing pure virtual functions are called abstract classes. All member functions are pure virtual functions.

 

Class C2 {<br/> virtual void a () = 0; <br/>}; <br/> void C2: (){}

If the subclass that inherits abstract classes does not implement pure virtual functions, this subclass is also an abstract class. An abstract class cannot declare an instance.


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.