When i use it with Sprite everything is ok. (ex: Vector<Sprite*> mySprites; …).
But when i use it with my own class (and it inherits cocos2d::Sprite class, ex: Vector<MyNewSprite*> mySprites) it raise an error when compile: error C2338: Invalid Type for cocos2d::Vector!
Furthermore, when i use it with cocos2d::Point (Vector myPoints), the same error happens.
Is it a bug or limitation of this data structure?
Take care that you implement the static create-function for your own classes. For example this class works for cocos2d::Vector
class MySprite : public cocos2d::Sprite
{
public:
MySprite()
{
}
static MySprite* MySprite::create(const char* name)
{
MySprite* spr = new MySprite();
if (spr->initWithFile(name))
{
// your own stuff
return spr;
}
CC_SAFE_RELEASE(spr);
}
};
And then it’s totally ok to do:
auto mysprite = MySprite::create("HelloWorld.png");
cocos2d::Vector<MySprite*> mspVec;
mspVec.pushBack(mysprite);
Reason why you need to implement the create method is, that you create vectors of your derived class type, but the default create method returns parent class type, which is not convertible to your derived class type.