Coco2dx 游戏项目接入SDK时遭遇C/C++ 与 Object-C混编,此时该怎么办?


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文件中写入接口。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值