简体   繁体   中英

How is a pointer to a member function different than a pointer to a data member?

So I have this alias template:

template<class MemberT, class ClassT>
using make_member_ptr = MemberT ClassT::*;

And I noticed that make_member_ptr<int(char, long), class_type> is the same that int(class_type::*)(char, long) . Before, I was thinking that a pointer to a member function is completely different to a pointer to a data member.

How do pointers to member functions differ from pointers to data members?

The only thing that I could find is that if the member function is virtual, calling through a pointer to the base function will call the derived function, which is a non-issue for pointers a non-function member.

The reason I am asking is that I am dealing with generic pointers to members, and I want to know what I have to look out for and special case for pointers to member functions vs data members.

Before, I was thinking that a pointer to a member function is completely different to a pointer to a data member.

You've thought correctly.

How do pointers to member functions differ from pointers to data members?

They are separate types. They may have different sizes. Pointer to a member function can point to a member function. Pointer to a data member can point to a data member. The difference is analogous to the one between function pointers and data pointers.

make_member_ptr<int(char, long), class_type> is a pointer to member function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM