包括c头文件在c ++文件 [英] including c header in c++ file

查看:238
本文介绍了包括c头文件在c ++文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在cpp文件中包含一个c头文件。
c头文件具有关键字Boolean。



c头像这样:

  #ifndef _CONFIGSTORE_H_ 
#define _CONFIGSTORE_H_

#ifdef __cplusplus
externC
{
# endif
Boolean ConfigStoreIsPassword(char * pName);

#ifdef __cplusplus
}
#endif

#endif // _ CONFIGSTORE_H_

下面是我在cpp文件中包含c头的方法:

  externC{
#includeconfigstore.h
}

  #ifdef __cplusplus 
externC
{
#endif

#includeconfigstore.h

#ifdef __cplusplus
}
#endif
pre>

无论哪种方式,我得到以下错误:
../../../../src/Common/framework/configstore .h:52:error:'Boolean'不指定类型



你能否让我知道如何在cpp文件中添加c头
先感谢!



-Vasavi

解决方案

在这里。一,你在另一个 externC块中嵌套一个 externC删除外部块。



两个,布尔不是c ++中的关键字。 bool 是。请尝试在头包含之前添加 typedef bool Boolean;


I am trying to include a "c" header file in a cpp file. The c header file has the keyword "Boolean".

c header looks something like this:

#ifndef _CONFIGSTORE_H_
#define _CONFIGSTORE_H_

#ifdef __cplusplus
extern "C"
{
#endif
Boolean ConfigStoreIsPassword(char *pName);

#ifdef __cplusplus
}
#endif

#endif //_CONFIGSTORE_H_

Below is the way i am including the c header in my cpp file:

extern "C"{
#include "configstore.h"
}

or

#ifdef __cplusplus
extern "C"
{
#endif

#include "configstore.h"

#ifdef __cplusplus
}
#endif

Either way i include, i get the below error: ../../../../src/Common/framework/configstore.h:52: error: 'Boolean' does not name a type

Could you please let me know how i can add the c header in cpp file Thanks in advance!!

-Vasavi

解决方案

Two things spring to mind here. One, you are nesting an extern "C" block inside another extern "C" block. Remove the outer blocks.

Two, Boolean is not a keyword in c++. bool is. Try adding typedef bool Boolean; before your header inclusion.

这篇关于包括c头文件在c ++文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆