C 函数中调用 C++函数
来源:互联网 发布:最美古诗词知乎 编辑:程序博客网 时间:2024/04/29 11:13
// cpp.h
#ifndef __cpp_h__
#define __cpp_h__
class class1 {
class1();
~class1();
public:
int I;
int J;
int getI(void);
};
#endif
// end file
// cpp.cpp
#i nclude "stdafx.h"
#i nclude <iostream>
#i nclude "cpp.h"
#i nclude "c.h"
using namespace std; // 打开标准库名字空间
class1::class1()
{}
class1::~class1()
{}
int class1::getI(void)
{
return I++;
}
// 按 C 调用方式编译下面函数
extern "C"
int get_class1_I(struct1 * p)
{
class1 * pClass1 = (class1 *)p;
cout << "c++: " << pClass1->getI() << endl;
return pClass1->getI();
}
// end file
// c.h
#ifndef __c_h__
#define __c_h__
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int i; // 与 class1 类中变量一致
int j;
}struct1;
#ifdef __cplusplus
}
#endif
#endif
// end file
// c.c
#i nclude <cstdio>
#i nclude "c.h"
extern int get_class1_I(void * p);
struct1 s;
int main(void)
{
printf ("c: %d/n", get_class1_I(&s));
printf ("c: %d/n", get_class1_I(&s));
return 0;
}
// end file
参考了eCos中的混和编程实现方式(http://sources.redhat.com/ecos/)。
本例在ADS 1.2中编译通过,执行结果正确。
VC++中编译时,C.C文件编译选项中选择 Not using precompile headers。
- C中调用C++函数 C++中调用C函数
- c中调用c++函数
- C中调用C++函数
- C中调用C++函数
- C中调用C++函数
- c中调用c++函数
- C中调用Lua函数
- Lua中调用C函数
- C中调用Lua函数
- python调用c中函数
- c中调用Lua函数
- C 函数中调用 C++函数
- C 函数中调用 C++函数
- C 函数中调用 C++函数
- C++:构造函数中调用虚函数
- C++:构造函数中调用虚函数
- ios object-c 中调用c函数
- J2ME中调用系统API C函数
- escape()、encodeURI()、encodeURIComponent()区别详解
- 关于汉诺塔问题
- 《路由器配置与管理完全手册——Cisco篇》目录抢鲜暴光
- 关于Android中Spinner的使用
- 《Windows内核编程》---基本数据结构
- C 函数中调用 C++函数
- 写些新文章吧!
- jquery技巧1-简化表单初始化
- 循环冗余校验法
- 为了我的许多想法,我要努力~~~~~~~~~大家也一样啊
- 离家的日子
- 很完善的PHP转跳代码
- 测试CSDN' Bug
- 递归算法转换为非递归算法