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