A pointer to a class member function is not actually a pointer _c language

Source: Internet
Author: User

1, unlike regular pointers, a pointer to a member does not point to a specific memory location, it points to a specific member of a class, rather than to a specific member in a particular object. Usually the clearest way to do this is to look at the pointer to a data member as an offset.

This offset tells you how many bytes a particular member's position is from the beginning of the object.

2, given a member's offset within the class, in order to access the data member at that offset, we need the address of an object of the class. This is when you need. * and->* operations. PC->*PIMC, requests that the address within the PC be added to the offset within the PIMC in order to access the appropriate data member in the C object that the PC points to. AC.*PIMC, the address of the request AC plus the deviation in the PIMC is also to access the appropriate data member in the C object that the PC points to.
Ps:
* Member pointer dereference operator (. *) Get Member from object or reference
The * Member pointer arrow operator (->*) Gets the member through the object's pointer

3. To obtain the address of a non-static member function, you get not an address, but a pointer to a member function.

4. In order to dereference a pointer to a member function, you need an object or a pointer to the object. In the case of a pointer to a data member, to access the member, you need to add the address of the object and the offset of the member. For a pointer to a member function, you need to use the address of the object as the value of the this pointer, make a function call, and use it for other purposes.

5. The implementation of a pointer to a member function must store some information, such as whether the member function it points to is virtual or non-virtual, where the appropriate virtual function table pointer is found, and so on.

6. Add another point about the pointer to an inline function. It is legal for a function pointer to point to an inline function. However, calling inline functions through function pointers will not result in inline function calls because the compiler cannot precisely determine what functions will be invoked at compile time. So at the call point, the compiler has no alternative but to generate an indirect, non-inline function call code.

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.