vc 与oc混编
来源:互联网 发布:hf线切割编程软件 编辑:程序博客网 时间:2024/06/01 20:51
步骤:
1.c++
- // People.h
- #ifndef __MXCPPTest__People__
- #define __MXCPPTest__People__
- #include <iostream>
- class People
- {
- public:
- void say(const char * words);
- };
- #endif
-----------------
- //
- // People.cpp
- // MXCPPTest
- //
- // Created by fengshaobo on 12-11-27.
- // Copyright (c) 2012年 fengshaobo. All rights reserved.
- //
- #include "People.h"
- void People::say(const char *words)
- {
- std::cout << words << std::endl;
- }
2.oc封装
- //
- // Student.h
- // MXCPPTest
- //
- // Created by fengshaobo on 12-11-27.
- // Copyright (c) 2012年 fengshaobo. All rights reserved.
- //
- #import <Foundation/Foundation.h>
- #import "People.h"
- @interface Student : NSObject
- {
- People *p;
- }
- - (void)say:(NSString *)words;
- @end
-----------------
- //
- // Student.mm
- // MXCPPTest
- //
- // Created by fengshaobo on 12-11-27.
- // Copyright (c) 2012年 fengshaobo. All rights reserved.
- //
- #import "Student.h"
- @implementation Student
- - (void)say:(NSString *)words
- {
- p->say([words UTF8String]);
- }
- @end
3.将.m -> .mm
- //
- // ViewController.mm
- // MXCPPTest
- //
- // Created by fengshaobo on 12-11-27.
- // Copyright (c) 2012年 fengshaobo. All rights reserved.
- //
- #import "ViewController.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- Student *s = [[Student alloc] init];
- [s say:@"hello world!"];
- [s release];
- s = nil;
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- @end
0 0
- vc 与oc混编
- Swift与OC混编
- OC与Swift混编
- oc 与 c++混编
- c++与oc混编
- OC与Swift混编
- OC与Swift混编
- OC与Swift混编
- OC与Swift混编
- OC与Swift混编
- oc与swift混编
- Swift与OC 混编
- Swift与OC混编
- OC与Swift混编
- OC与Swift混编
- swift 与oc 混编
- Swift与OC混编
- OC与swift混编
- 黑马程序员--内部类
- spoj 375 Query on a tree 树链剖分
- Qt release之后运行显示it could not find or load the Qt platform plugin "windows".解决方法
- [ExtJS5学习笔记]第十四节 Extjs5中data数据源store和datapanel学习
- 【DP】 HDOJ 4834 JZP Set
- vc 与oc混编
- 游戏开发-----想要学习游戏开发的童靴请进来,也许我能帮到你
- 最长公共子序列
- XP设备管理器错误代码
- IOS——Block
- erlang OTP设计原理文档
- excel VBA学习
- TCP/IP详解学习笔记(9)-TCP协议概述
- 关于json 的使用