constexpr of static tuple class member has linker error

后端 未结 2 1745
[愿得一人]
[愿得一人] 2021-01-18 16:10

I have the following code:

#include 
#include 

class T
{
    public:
        using Names = std::tuple

        
2条回答
  •  一整个雨季
    2021-01-18 16:50

    @Columbo posted the correct solution.

    Unfortunately I am trying to build a header only library. The solution requires that the static member be compiled into one compilation unit (which is what I was using constexpr in the hopes of avoiding).

    So I needed to stick another twist into the works to make it work. This is just to share my solution:

    #include 
    
    class T
    {
        public:
            using Names = std::tuple;
            template
            static char const* getName()
            {
                static constexpr Names names {"First", "Second"};
                return std::get(names);
            }
    };
    
    int main()
    {
        std::cout << T::getName<0>() << "\n";
    }
    

提交回复
热议问题