gpt4 book ai didi

c++ - 在 C、VS 2010 中包含 C++ 头文件

转载 作者:搜寻专家 更新时间:2023-10-31 01:53:47 27 4
gpt4 key购买 nike

我想写一个 C 代码,比如“test.c”,然后从中调用一些 C++ 函数。

我有一个头文件header.h,其中定义了函数和一个包含函数定义的 C++ 文件。

我无法弄清楚编译命令以及如何使用 extern 命令。有人可以澄清一下吗?

最佳答案

I want to write a C code, say "test.c" call some C++ functions from it.

在标题中尝试这样的内容:

#ifdef __cplusplus
extern "C"
{
#endif
void foo (void);
#ifdef __cplusplus
};
#endif

然后在您的 .cpp 文件中实现 foo()。确保您的 .cpp 文件还包含 header 。

关于c++ - 在 C、VS 2010 中包含 C++ 头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10647020/

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