Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 类主体外的模板定义:VC2010 vs GCC 4.9_C++_Visual Studio 2010_Templates_Arguments_Definition - Fatal编程技术网

C++ 类主体外的模板定义:VC2010 vs GCC 4.9

C++ 类主体外的模板定义:VC2010 vs GCC 4.9,c++,visual-studio-2010,templates,arguments,definition,C++,Visual Studio 2010,Templates,Arguments,Definition,我可以用GCC4.9编译这段代码 struct Space2 { static const int Size = 2; }; struct Space3 { static const int Size = 3; }; template <typename Space> struct A { void f(int a[Space::Size]); //error C2244 }; template <typename Space> void A<Sp

我可以用GCC4.9编译这段代码

struct Space2 {
  static const int Size = 2;
};

struct Space3 {
  static const int Size = 3;
};

template <typename Space>
struct A {
  void f(int a[Space::Size]); //error C2244
};

template <typename Space>
void A<Space>::f(int a[Space::Size]) {
}

int main() {
  typedef Space2 Space;
  int a[Space::Size];
  A<Space> m;
  m.f(a);
  return 0;
}
但我在VC2010编译器中有一个错误:

error C2244: 'A<Space>::f': unable to match function definition to an existing declaration  
main.cpp(11): see declaration of 'A<Space>::f' definition  
'void A<Space>::f(int [Space::Size])'     
existing declarations  
'void A<Space>::f(int [Space::Size])'
为什么?


另外,当我把f的定义放到A中时,这段代码在GCC4.9和VC2010中都编译得很好

看起来像MSVC中的一个bug。在VS2013中运行良好。避免在旧的工具版本上被卡住,这些C++中有很多变化。如果从参数DECL中删除尺寸大小的话,它也可以正常工作。然而,它仍然会吐出int&a[Space::Size],这让我有些吃惊。可能与此有关: