VS2008 C + + Object memory layout (6): Pointer to member function

Source: Internet
Author: User

VS supports pointers to member functions, which are tested using the class above:

Class Cparenta
{
Public
int parenta_a;
int parenta_b;

Public
virtual void parenta_f1 () {this->parenta_a = 0x10;}
virtual void Parenta_f2 () {this->parenta_a = 0x20;}

Public
void Parenta_f3 () {this->parenta_a = 0x30;}
void Parenta_f4 () {this->parenta_a = 0x40;}
};

Class CPARENTB
{
Public
int parentb_a;
int parentb_b;

Public
virtual void parentb_f1 () {this->parentb_a = 0x50;}
virtual void Parentb_f2 () {this->parentb_a = 0x60;}

Public
void Parentb_f3 () {this->parentb_a = 0x70;}
void Parentb_f4 () {this->parentb_a = 0x80;}
};

Class Cchild:public Cparenta, public cparentb
{
Public
int child_a;
int child_b;

Public: function of//subclass
virtual void child_f1 () {this->child_a = 0x90;}
virtual void Child_f2 () {this->child_a = 0xa0;}

Public://non-overloaded functions
void Child_f3 () {this->child_a = 0xb0;}
void Child_f4 () {this->child_a = 0xc0;}

Public://functions that overload the parent class A
virtual void Parenta_f2 () {this->child_a = 0xd0;}
virtual void parenta_f1 () {this->child_a = 0xe0;}

Public://functions that overload the parent class B
virtual void Parentb_f2 () {this->child_a = 0xf0;}
virtual void parentb_f1 () {this->child_a = 0xFF;}
};


Cchild Child, *pchild;
Cparenta parent, *pparent;

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.