0
下面的代码失败,G ++ 4.8.2链接:类constexpr表达
#include <map>
struct Foo
{
constexpr static int foo = 1;
};
static std::map<int, int> map {{1, Foo::foo}};
int main()
{
return Foo::foo;
}
我得到以下错误:
g++ -std=c++11 -o foo foo.cc
/tmp/ccZXCwiK.o: In function `__static_initialization_and_destruction_0(int, int)':
foo.cc:(.text+0x51): undefined reference to `Foo::foo'
如果我注释掉地图,事情链接正好。这是一个编译器错误,还是在标准中我缺少一些特殊情况?
@LightnessRacesinOrbit http://coliru.stacked-crooked.com/a/d9da4dacc301287d –
@ JohannesSchaub-litb:感谢 –
再次,一个'+'神奇修复的东西:'静态的std ::地图地图{{1 ,+ Foo :: foo}};'工作正常。 –
dyp