使用std :: map的Visual Studio 11编译时错误

Sca*_*nth 6 c++ gcc compiler-errors visual-studio

以下代码使用gcc-4.5.1编译,但不在Visual Studio 11中编译.

#include <map>
#include <array>

typedef std::pair<const unsigned int, std::array<const unsigned int, 4>> pairus;

int main(){

   std::map<const unsigned int, std::array<const unsigned int, 4> > x; 
   std::array<const unsigned int, 4> troll = {1, 2, 3, 4};
   x.insert(pairus(1, troll));

   auto z = x[1];
}
Run Code Online (Sandbox Code Playgroud)

1现在映射到std::array<> troll.插入效果很好,程序编译.但是,只要我尝试auto z = x[1]- >因此尝试获取1映射到的数组troll,程序不会编译时出现以下错误:

error C2512: 'std::array<_Ty,_Size>::array' :没有适当的默认构造函数可用

什么导致gcc和vs11之间的行为差​​异以及如何解决它?

谢谢.

Ker*_* SB 4

尝试auto z = *x.find(1);一下。-运算[]符需要默认可构造类型。事实上,整个容器需要一个默认可构造的类型,因此当您尝试各种实现时,除了随机运气之外,您真的不能指望任何东西。