编译器错误 C2894

来源:互联网 发布:linux内核编译 ubuntu 编辑:程序博客网 时间:2024/05/17 04:07

模板不能声明为有“C”链接

此错误可能是由 extern “C”块内部定义的模板导致的。

下面的示例生成 C2894:

// C2894.cppextern "C" {   template<class T> class stack {};   // C2894 fail      template<class T> void f(const T &aT) {}   // C2894}

下面的示例生成 C2894:

// C2894b.cpp// compile with: /cextern "C" template<class T> void f(const T &aT) {}   // C2894template<class T> void f2(const T &aT) {}   // OK


转自:http://msdn.microsoft.com/zh-cn/library/vstudio/95bhc9c2.aspx