你好,游客 登录 注册 搜索
背景:
阅读新闻

C函数和C++函数相互调用

[日期:2013-05-10] 来源:Linux社区  作者:zuocheng_liu [字体:大 中 小]

C函数和C++函数相互调用

test.c

int call_MyMath_sum (int,int);
 
int sum(inta , intb) {
 return call_MyMath_sum(a,b);
}

main.cpp

#include <iostream>
 using namespace std;
 
extern"C" {
 int sum(int, int);
 }
 
class MyMath {
 public:
    static int sum(int, int);
 };
 intMyMath::sum(inta, intb) {
    return(a + b);
 }
 
extern"C" int call_MyMath_sum (inta , intb) {
    return(MyMath::sum(a,b));
 }
 
int main(void) {
    cout<<sum(5,6);
    return0;
 }

Makefile

main.o:
  g++ -c -o main.o main.cpp
test.o:
  gcc -c -o test.o test.c
main: main.o test.o
  g++ -o main main.o test.o
all: clean main
clean:
  rm -f test.o main.o

linux
相关资讯       C函数调用 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款