c调用c++函数

#ifndef CPPFUNCTIONS_H_
#define CPPFUNCTIONS_H_
#ifdef __cplusplus
int cpp_func(int input);
extern "C" {
#endif
int c_func(int input);
#ifdef __cplusplus
}
#endif
#endif /* CPPFUNCTIONS_H_ */
#include "CppFunctions.h"
int cpp_func(int input) {
 return 5;
}
int c_func(int input) {
 return cpp_func(input);
}
#include <stdio.h>
#include "CppFunctions.h"
int main(int argc, char **argv) {
 printf("%d\n", c_func(10));
 return 0;
}

转载,已验证OK

猜你喜欢

转载自www.cnblogs.com/dianrain/p/10946514.html