Pointer to member: works in GCC but not in VS2015

前端 未结 3 1597
难免孤独
难免孤独 2021-02-13 10:54

I\'m trying to implement a \"property\" system to convert C++ instances into JSON and vice versa. I took a part of the code from Guillaume Racicot\'s answer in this question (C+

3条回答
  •  一整个雨季
    2021-02-13 11:32

    If it is absolutely needed to properties be defined in User class maybe you could make use of helper templated constexpr function like:

    #include 
    
    template 
    struct Property {
        constexpr Property(T Class::* const member) : m_member{ member } {}
    
        T Class::* const m_member;
    };
    
    template 
    constexpr Property get_age_property() {
        return  Property(&T::age);
    }
    
    class User
    {
    public:
        int age;
    
        constexpr static std::tuple> properties = std::make_tuple(
             get_age_property()
        );
    
    };
    
    int main()
    {
    }
    

    It seems to compile in webcompiler i.e. VC++ 19.00.23720.0

提交回复
热议问题