Chinaunix首页 | 论坛 | 博客
  • 博客访问: 377049
  • 博文数量: 82
  • 博客积分: 1855
  • 博客等级: 上尉
  • 技术积分: 846
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-12 12:28
文章存档

2013年(3)

2012年(8)

2011年(71)

分类: C/C++

2011-04-23 18:37:44

1.

#ifdef __cplusplus

extern "C"

{

#endif

//函数声明

#ifdef __cplusplus

}

#endif

//C中引用C++函数

C中引用C++语言中的函数和变量时,C++的函数或变量要声明在extern "C"{}里,但是在C语言中不能使用extern "C",否则编译出错。

//test.cpp

#include

extern "C"

{

void mytest()

{

printf("mytest in .cpp file ok\n");

}

}

//main.c

void mytest();

int main()

{

mytest();

return 0;

}

阅读(961) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~