Print address of virtual member function

后端 未结 5 1283
眼角桃花
眼角桃花 2020-12-01 13:57

I am trying to print the address of a virtual member function. If I know which class implements the function I can write:

print(\"address: %p\", &A::func         


        
5条回答
  •  醉话见心
    2020-12-01 14:20

    Pointers to member functions are not always simple memory addresses. See the table in this article showing the sizes of member function pointers on different compilers - some go up to 20 bytes.

    As the article outlines a member function pointer is actually a blob of implementation-defined data to help resolve a call through the pointer. You can store and call them OK, but if you want to print them, what do you print? Best to treat it as a sequence of bytes and get its length via sizeof.

提交回复
热议问题