Getting the type of a member

前端 未结 3 1470
鱼传尺愫
鱼传尺愫 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条回答
  •  -上瘾入骨i
    2021-01-04 03:03

    In C++2003 it can't be done directly but you can delegate to a function template which deduces the type:

    template 
    void deduce_member_type(T S::* member) {
         ...
    }
    
    int main() {
        deduce_member_type(&Person::age);
    }
    

提交回复
热议问题