小编arm*_*007的帖子

如何在静态constexpr类成员中使用make_tuple()?

我想用make_tuple()constexpr.它适用于全球范围.但它会为static constexpr类成员生成链接错误.

#include <iostream>
#include <tuple>

using namespace std;

class A
{
public:
    static constexpr auto z = make_tuple(5, 3.0);
};

constexpr auto tp = make_tuple(6, 3.2);

int main()
{

    cout << get<0>(tp) << " " << get<1>(tp) << endl; // OK

    cout << get<0>(A::z) << "  " << get<1>(A::z) << endl; // error: (.text+0x5a): undefined reference to `A::z'
                                                          //        (.text+0x67): undefined reference to `A::z'

}
Run Code Online (Sandbox Code Playgroud)

我已经检查了这里 make_tuple本身不是constexprc++11.我猜这不是问题.如果是,它将生成编译错误而不是链接错误. …

c++ constexpr c++11

2
推荐指数
1
解决办法
549
查看次数

标签 统计

c++ ×1

c++11 ×1

constexpr ×1