CCSprite inheritance and virtual method access problem

Hi, I’m quiet newbie on cocos2d-x and c++ (I’m familiar with Java)
I’m facing on an inheritance and accessing virtual method problem.

//A.h
class A : public CCSprite
{
    public:
        virtual void select() = 0;
}
//B.h
class B : public A{
    public:
        virtual void select();
}
//select is implemented in B.cpp

//C.h
class C : public B{
   //doesn't impl select to use B's select();   
}
//D.h
class D : public B{
    public:
        void select(); // use own select();
}

Above is my basic structure.
And, when I try to create object like below, some memory accessing violation occurred.

A* elem = (C*)CCSprite::create("images/b.png", CCRectMake(0,0,48,48));
elem->select(); // error occurred!

How do I fix it?

CCSprite::create() creates instance of CCSprite class, not C neither A.

You should overload create() in your subclass and use it. Cocos2d-x has common create method structure, for example it’s CCSprite::create code: http://pastebin.com/2WyVpiqi

Cool. Just what I suspected.
Appreciate for your help :wink:

Sergey Shambir wrote:

CCSprite::create() creates instance of CCSprite class, not C neither A.
>
You should overload create() in your subclass and use it. Cocos2d-x has common create method structure, for example it’s CCSprite::create code: http://pastebin.com/2WyVpiqi