意外调用copyWithZone c ++ cocos2d

时间:2012-10-17 12:20:05

标签: c++ cocos2d-iphone copywithzone

我遇到了一些麻烦。

我做了一些接口(c ++中的抽象类)。在我的类中实现它(也来自CCObject)。 在第三类中,我尝试调用接口方法并获得SIGABORT。这里是代码

 //interface class


class CallBackInterface
 {
 public:
       virtual void SomeMethod() = 0;
 };

 //my class that implement the interface 
 class MyClass : public CallBackInterface, public CCObject
 {
 public:
       void SomeMethod(){/*some realization*/}; 
 };

 //class that invoke the SomeMethod


class CallBacker()
 {
 public:
       CallBackInterface* callBackObject;
 };

 //main code


CallBacker* callBacker = new CallBacker();
 MyClass* myClass = new MyClass();
 callBacker->callBackObject = myClass;

/*
this string generate unexpected invoke of copyWithZone method CCObject's class
with SIGABORT. */

callBacker->callBackObject->SomeMethod();

/*
In debugger mode I see that SomeMethod don't invoke (debugger don't  go                                into it). Here the copyWithZone*/

CCObject* CCCopying::copyWithZone(CCZone *pZone)
    {
        CC_UNUSED_PARAM(pZone);
        CCAssert(0, "not implement"); <<- here is SIGABORT
        return 0;
    }

copyWithZone调用崩溃了我的应用

1 个答案:

答案 0 :(得分:0)

class CallBackInterface : public CCObject
{
public:
     virtual void SomeMethod() = 0;
};

class MyClass : public CallBackInterface
{
     void SomeMethod(){}
};

试试这个!我之前遇到过同样的问题。