libtorch Compiler Error C2951

 

Compiler Error C2951

https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2951?view=vs-2017

类型声明只能在全局、命名空间或类范围内使用

不能在全局或命名空间范围之外声明泛型类或模板类。 如果在包含文件中进行泛型声明或模板声明,请确保包含文件位于全局范围内。

 

// C2951.cpp
template 
class A {};

int main() {
   template    // C2951
   class B {};
}

C2951 can also occur when using generics:

Copy

// C2951b.cpp
// compile with: /clr /c

// OK
generic 
ref class GC { };

int main() {
   generic  ref class GC2 {};   // C2951
}

 

解决方法:换vs2017

参见:https://blog.csdn.net/jacke121/article/details/88736214

参考:

https://stackoverflow.com/questions/21683334/return-type-dependent-on-template-parameter

 

你可能感兴趣的:(c++)