我想用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本身不是constexpr在c++11.我猜这不是问题.如果是,它将生成编译错误而不是链接错误. …