您的位置:首页 > 编程语言 > C语言/C++

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

2013-04-27 11:45 253 查看
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


原网址 :http://it.zuocheng.net/?p=32

参考网址: C中调用C++与C++调用C
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: