Getting the type of a member

前端 未结 3 1468
鱼传尺愫
鱼传尺愫 2021-01-04 02:24

NOTE: This question was originally asked way back in 2012. Before the decltype specifier was fully implemented by any major compilers. You shou

3条回答
  •  孤街浪徒
    2021-01-04 03:06

    template  M get_member_type(M T:: *);
    
    #define GET_TYPE_OF(mem) decltype(get_member_type(mem))
    

    Is the C++11 way. It requires you to use &Person::age instead of Person::age, although you could easily adjust the macro to make the ampersand implicit.

提交回复
热议问题