Note that there are some explanatory texts on larger screens.

plurals
  1. POCocos2d C++ Inheriting from a Virtual Class cuses a Linker error
    primarykey
    data
    text
    <p>I'm trying to do something similiar to an instance which hinerit from a @Protocol in Objective-C, so I would like to have a @Protocol with some declared methods, and an instance where I can override and use my methods.</p> <p>With C++ for now I did a class with virtual methods liket his:</p> <pre><code>class MyClassA { public: ~MyClassA(){}; virtual void doSomething(argument *) = 0; } </code></pre> <p>and a class (the one I want to instantiate and use)</p> <pre><code>class MyClassB : public MyClassA { public: ~MyClassB() {}; void doSomething(argument *a); } </code></pre> <p>in the implementation file of both these classes I've implemented doSomething() like this:</p> <pre><code>void doSomething(argument *a) { // yep do something } </code></pre> <p>then in AnotherObject (which is a subclass of CCNode) I want to create an ivar of MyClassB and here's where I'm failing at, I tried to put a simple pointer to the class like:</p> <pre><code>MyClassB *myB; </code></pre> <p>and then use it like:</p> <pre><code>myB-&gt;doSomething; </code></pre> <p>but obviously it's going to crash with bad_access </p> <p>I tried to instantiate the object before using </p> <pre><code>MyClassB *myB = new MyClassB; </code></pre> <p>or </p> <pre><code>MyClassB *myB = MyClassB::create(); </code></pre> <p>but got a linker error whatever I try. The error says:</p> <pre><code>Undefined symbols for architecture i386: "MyClassB::doSomething(argument*)", referenced from: AnotherObject::init() in AnotherObject.o "vtable for MyClassB", referenced from: AnotherObject::init() in AnotherObject.o </code></pre> <p>I'm missing something to achieve the same as </p> <pre><code>id&lt;Protocol&gt;object; </code></pre> <p>with objective-C which I know better than C++</p> <p>ps. I've decided to write Cocos2d even if this is a C++ question because of the init and create_func method that probably are in some way related</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload