gpt4 book ai didi

c++ - 智能感知 :expected a declaration in C++

转载 作者:行者123 更新时间:2023-11-28 07:49:30 24 4
gpt4 key购买 nike

我正在尝试将 C 和 C++ 代码添加到一起,但最终出现上述错误,如 IntelliSense:expected a declaration

例如abc.cpp

#include "abc.h"
#ifdef __cplusplus
extern "C"
{
#endif
#include "C_headerfiles.h"
...
...//Body of C code
#ifdef _cplusplus
}
#endif
...
...//Body of C plus plus code

#ifdef __cplusplus
extern "C" //`IntelliSense:expected a declaration
{
#endif
...
...//Body of C code
#ifdef _cplusplus
}
#endif

最佳答案

我已经解决了这个问题:需要添加extern C only once not again and again

#include "abc.h"
#ifdef __cplusplus
extern "C"
{
#endif
#include "C_headerfiles.h"
...
...//Body of C code

...
...//Body of C plus plus code


...
...//Body of C code
#ifdef _cplusplus
}
#endif

关于c++ - 智能感知 :expected a declaration in C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14156532/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com