从C+调用C函数+;同名 我已经读过了,但是如果C++和C中的两个函数有相同的名称,我不知道该怎么做。C函数已经在头文件中用if#ifdef_uucplusplus保护。 所以我有一个.cpp文件 foo (int a, int b) { //calling from C foo (int a, int b, int c) }

从C+调用C函数+;同名 我已经读过了,但是如果C++和C中的两个函数有相同的名称,我不知道该怎么做。C函数已经在头文件中用if#ifdef_uucplusplus保护。 所以我有一个.cpp文件 foo (int a, int b) { //calling from C foo (int a, int b, int c) },c++,c,C++,C,谢德尔 #ifdef __cplusplus extern "C" { #endif void foo(int a,int b, int c); #ifdef __cplusplus } #endif 文件.c #include "Cheader.h" void foo(int a,int b, int c) { /* ... */ } C++头文件 Cplusplusheader.hpp void foo(int a, int b);

谢德尔

#ifdef __cplusplus
extern "C" {
#endif

void foo(int a,int b, int c);

#ifdef __cplusplus
}
#endif
文件.c

#include "Cheader.h"

void foo(int a,int b, int c)
{
    /* ... */
}
C++头文件

Cplusplusheader.hpp

void foo(int a, int b);

C++


我刚刚做了一个例子来测试它,你可以把它当作其他函数来调用。编译器似乎理解C fo只是C++ C++的一个重载。下面是一个例子:

main.cpp

//main.cpp
#包括
#包括“header.h”
//c++foo
无效foo(整数m1,整数m2)
{
foo(num1);
foo(num2);

STD::Cout你能进一步解释你是如何调用C++函数的C++以及如何构造这个项目的?answers@HazemAbaza问题是什么?希望检查一个明显的注释,但是
foo(inta,intb,intc)
不是对函数的调用:您可能是指类似于
foo(a,b,100);
之类的内容。请将您的代码更新为您遇到问题的实际代码,以便我们也可以尝试。
CplusPlus.cpp

#include "Cplusplus.hpp"
#include "Cheader.h"

void foo(int a, int b)
{
    foo(a,b,c); // call C function
    // ...
}

The number is: 10
The number is: 10
Sum: 20