c++ oc

来源:互联网 发布:如何查淘宝搜索热度 编辑:程序博客网 时间:2024/06/07 20:52

object-c---C++相互调用


1.parent.h 虚类

/* 对外边 C++ 文件的接口只用 parent.h 文件 调用 parent *p = createChildren(); */#include "cocos2d.h"class parent{public:    bool isFull;    int  typeTag;public:    parent(){};    ~parent(){};    virtual void callChildren() = 0;};extern parent* createChildren();


2.children.h

#import <MediaPlayer/MediaPlayer.h>//引进用到的 object-c 头文件#include "parent.h"#include "cocos2d.h"USING_NS_CC;class children : public parent{private:    MPMoviePlayerController *player;//可以定义 object-c 变量    public:    children();    ~children();      void callChildren();};


3.children.mm

#include "children.h"#import "EAGLView.h"using namespace std;//Object-c 类@interface ObjectC : NSObject{}- (void) callObjectC:(int) cint;@end@implementation ObjectC- (void) callObjectC:(int) cint{    NSLog(@"call object %d", cint);}@endstatic ObjectC *s_oc = nil;static parent *s_parent;//C++类的实现parent* createChildren(){    s_parent = new children();    return s_parent;}void children::callChildren(){    /*可以创建 object-c 对象*/    s_oc = [ObjectC alloc];    [s_oc callObjectC: 1];}children::children(){}children::~children()//释放object-c 和 c++ 对象{    [s_oc release];}























0 0
原创粉丝点击