C ++ function call

Source: Internet
Author: User

The member functions of C ++ are essentially similar to those of C. I think their function addresses are fixed.

For example

Class

{

Public:

Void F1 (){}

Virtual F2 ();

Void F3 () {m_value = 0 ;}

PRIVATE:

Int m_value;

};

The address of F1, F2, and F3 is fixed. When each object calls a function, it only passes in the address pointer of the object itself, the function internally uses the this pointer to find information such as member variables and virtual function tables, because the member variables and virtual function tables are related to each object, and the function address is fixed,CodeSegment.

A * A = new ();

A * B = NULL;

A-> F1 (); // OK

A-> F2 (); // OK

A-> F3 (); // OK

B-> F1 (); // OK,

B-> F2 (); // error. This is null. An error occurred while searching the virtual function table.

B-> F3 (); // error. An error occurred while searching for the member variable m_value.

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.