
在用到C++和C混合编程时,C不能直接调用C++函数。
1、C++调用C的函数
在函数前面加extern “c”,意思是告诉编译器,该函数按照C语言规则来编译。
extern "C" int Add(int left,int right);
int main()
{
Add(1,2);
return 0;
}
2、C语言调用C++函数
被c函数调用的c++函数的声明放在一块语句块中:
#ifdef __cplusplus
extern "C" {
#endif
//函数声明
#ifdef __cplusplus
}
#endif