类体外的模板定义:VC2010与GCC 4.9

时间:2015-01-30 11:31:36

标签: c++ visual-studio-2010 templates arguments definition

我可以使用GCC 4.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])'

为什么?

P.S。当我将f的定义放入A时,此代码使用GCC4.9和VC2010编译得很好。

0 个答案:

没有答案
相关问题