Casting between void * and a pointer to member function

前端 未结 5 1889
故里飘歌
故里飘歌 2020-11-27 07:25

I\'m currently using GCC 4.4, and I\'m having quite the headache casting between void* and a pointer to member function. I\'m trying to write an easy-to-use li

5条回答
  •  一向
    一向 (楼主)
    2020-11-27 08:05

    It is possible to convert pointer to member functions and attributes using unions:

    // helper union to cast pointer to member
    template
    union u_ptm_cast {
        memberT classT::*pmember;
        void *pvoid;
    };
    

    To convert, put the source value into one member, and pull the target value out of the other.

    While this method is practical, I have no idea if it's going to work in every case.

提交回复
热议问题