1 首先新建一个.mm文件,该文件可以混编。并在文件中写入相关接口,供C/C++ 和 Object-C 去调用。
新加的文件
.mm中的实现以及.h中的声明。在这里使用了单例。
#ifndef __sgcard__occpp__
#define __sgcard__occpp__
#include <iostream>
namespace ppsgcard
{
class testForMM
{
public:
static testForMM * getInterface();
void payforGold(int serverID,int playIdx,int GoodsID ,char * billtittle);
void login();
};
}
#endif /* defined(__sgcard__occpp__) */
这里是实现
#include "occpp.h"
#include "AppController.h"
#include "RootViewController.h"
using namespace ppsgcard;
ppsgcard::testForMM* ppsgcard::testForMM::getInterface()
{
static ppsgcard::testForMM test;
return &test;
}
void testForMM::payforGold(int serverID, int playIdx, int GoodsID,char * billtittle)
{
[[AppController instance].viewController paygoods:serverID goodid:GoodsID idx:playIdx tittle:billtittle];
}
void testForMM::login()
{
[[AppController instance].viewController login];
}
2.如何使用
使用的地方包含头文件
这样C/C++代码就能随意调用O-C的方法。当然需要在occpp文件中写入接口。