Pointer to member: works in GCC but not in VS2015

前端 未结 3 1598
难免孤独
难免孤独 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:24

    My preferred workaround is just to replace the properties member data with a properties member function:

    class User
    {
    public:
        int age;
    
        constexpr static auto properties() { return std::make_tuple(
            Property(&User::age, "age")
        ); }
    };
    

    This works because in the definition of a member function, the class is considered to be completely defined. It also has the desirable attribute that properties doesn't need to be separately defined if odr-used.

提交回复
热议问题