错误C2894:无法声明模板具有"C"链接 [英] Error C2894: templates cannot be declared to have 'C' linkage
本文介绍了错误C2894:无法声明模板具有"C"链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨!
我正在使用Microsoft Visual C ++ 6.0.
我想在我的C ++代码中包含一个cs.h文件,如下所示:
Hi!
I''m working with Microsoft Visual C++ 6.0.
I want to I included a cs.h file in my C++ code like this:
extern "C"
{
#include "cs.h"
}
但是,当我使用时,出现以下错误:
d:\ program files \ microsoft visual studio \ vc98 \ include \ math.h(514):错误C2894:无法声明模板具有"C"链接
有人可以帮忙吗?
提前致谢. :)
But, when I use then I have the following error:
d:\program files\microsoft visual studio\vc98\include\math.h(514) : error C2894: templates cannot be declared to have ''C'' linkage
Can anyone help?
Thanks in advance. :)
推荐答案
错误消息不是全部说明吗?您的包含文件包括math.h,其中包含模板函数.模板不是C,因此您无法将其设置为extern "C"
.
因此,最大的问题是,为什么要将包含文件的完整内容粘贴在extern "C"
中?如果原始程序员打算在C程序中使用他或她的代码,那么他们会为您完成这项工作.由于没有,所以有以下两种选择之一:
-他们不打算在C程序中使用它
-他们确实打算将其从C程序中使用,但没有由C ++编译器进行编译
无论哪种方式,最好的选择就是修改源代码,这样就不需要客户端程序员来破解它.
干杯,
Ash
Doesn''t the error message say it all? Your include file is including math.h which contains a template function. Templates aren''t C so you can''t make themextern "C"
.
So the big question is why do you want to stick the complete contents of an include file in anextern "C"
? If the original programmer had intended his or her code to be used from a C program they''d have done that for you. As they haven''t there''s one of two options:
- They didn''t intend it to be used from a C program
- They did intend it to be used from a C program but not have it compiled by a C++ compiler
Either way the best bet is to modify the source so it doesn''t require the client programmer to hack around it.
Cheers,
Ash
我也有同样的问题!
这篇关于错误C2894:无法声明模板具有"C"链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文