C++ Converting function pointer to unique “hash” key

后端 未结 2 1245
一整个雨季
一整个雨季 2021-01-21 16:27

Se original question in the bottom.

I think I understand what you guys are saying now – that because the internal structure of the member function pointer is compiler/ma

2条回答
  •  清歌不尽
    2021-01-21 16:46

    You should be fine writing:

    reinterpret_cast(method)
    

    [edit] - for pointers to methods you will have to stay with c-style casts, as is explained in this SO: reinterpret_cast to void* not working with function pointers

    &method is as you suspec pointer to pointer, so its not what you want

    uintptr_t is better over int because it is guaranteed to be the same size as a pointer

提交回复
热议问题