object-c 混编 调用C,C++接口
2016-01-28 12:03
666 查看
xcode 支持 object-c 混编,在object-c 中调用c,c++接口
第一步 定义c语言 接口(File.c)
第二步 定义c++ 接口
student.h文件
student.cpp文件
第三步 将 object-c implementation文件名 .m 改称.mm 告诉编译器 混编
下面的例子是 object-c 调用接口
第一步 定义c语言 接口(File.c)
#include <stdio.h> void printsByC(){ printf("调用C语言。"); }
第二步 定义c++ 接口
student.h文件
#ifndef __test_hun__student__ #define __test_hun__student__ #include <iostream> #endif /* defined(__test_hun__student__) */
student.cpp文件
#include "student.h" using namespace std; class Student{ public: void getWeight(){ cout<<"Object C与C++混合编程。体重为:"<<weight<<"kg"; printf("调用C++语言。getWeight"); } void setWeight(int x){ weight = x; printf("调用C++语言。setWeigth"); } private: int weight; };
第三步 将 object-c implementation文件名 .m 改称.mm 告诉编译器 混编
下面的例子是 object-c 调用接口
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. printf("调用C语言。"); Human human; human.setWeight(26); human.getWeight(); Student *student=new Student(); student->getWeight(); delete student; }
相关文章推荐
- Objective-C和C++混编的要点
- 详解iPhone开发之Objective-C和 C 混编
- Xcode中C、C++、Object-C3种语言的混编
- 混合使用Objective-C,C++和Objective-C++
- Objective-C Runtime 运行时之一:类与对象(转载)
- TypeUtils -- Object 转为 强类型
- iOS开发-Objective-C与JavaScript交互
- Objective-C中类和方法的定义以及协议的使用
- Animation动画详解(七)——ObjectAnimator基本使用
- Objective-C Runtime 运行时与类的内部构造
- Bootstrap 多媒体对象(Media Object)
- bean和json相互转换工具类(工具ObjectMapper)
- Object-C 类,对象,运行时,isa 附带类本质的内存图
- 020: class, objects and instance: 一个简单的例子,压缩文件中内容的替换
- Selenium2(java)页面对象模型(Page Object) 八
- Objective-C与JavaScript交互的那些事
- RemObjects SDK 9.0 Beta_CodeFirst
- Objective-C 通知
- Error: while loading shared libraries: libXXX.so.X: cannot open shared object file: No such file
- Objective-C 单例