C ++ Normal Overload, virtual function overload, and pure virtual function overload

Source: Internet
Author: User

I didn't know much about these three types of heavy loads some time ago. There are some mixed concepts.
Today I made an example to test the functions
Different.

Base class:
Class
{
Public:
A ();
Void F1 ();
Virtual void F2 ();
Virtual void F3 () = 0;
Virtual ~ A ();

};

Subclass:
Class B: public
{
Public:
B ();
Void F1 ();
Void F2 ();
Void F3 ();
Virtual ~ B ();

};
Main function:
Int main (INT argc, char * argv [])
{
A * m_j = new B ();
M_j-> F1 ();
M_j-> F2 ();
M_j-> F3 ();
Delete m_j;
Return 0;
}

F1 () is a common overload.
When m_j-> F1 (); is called, F1 () in Class A is called.CodeIt will be fixed.
That is, the function of this class is called as defined by Class.
F2 () is a virtual function.
When m_j-> F2 () is called, it will call the corresponding function of the stored object in m_j. This is because of the new B
Object.
F3 () is the same as F2 (), but does not need to write function reality in the base class.

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.