Answer the question
In order to leave comments, you need to log in
Why does creating a static class member cause a linking error?
Created a project on cocos2d-x 3.10 with the aim of writing a remake of the Stack Attack game. I created a custom StackBlock class that describes the behavior of the box on the playing field and in the cocos2d-x main scene class I want to create a two-dimensional vector of pointers to the custom StackBlock class. + 2 auxiliary vectors, one of them contains the sum of blocks in a column, the other one contains the sum of blocks in a row.
As planned, the vector of rows will contain pointers to existing blocks or nullptr if there is no block. I thought that it would be more convenient if these vectors were created at the time of the scene initialization and further access to them would be from the functions of the StackBlock class and the player through the namespace of this scene, as is done with the scene initialization
Сlass EndlessMode : public cocos2d::Layer
{
public:
static std::vector<std::vector<StackBlock*> > VVMainGrid;
static std::vector<int> VIColumnWeight;
static std::vector<int> VIRowWeight;
// there's no 'id' in cpp, so we recommend returning the class instance pointer
static cocos2d::Scene* createScene();
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
virtual bool init();
// implement the "static create()" method manually
CREATE_FUNC(EndlessMode);
};
auto scene = EndlessMode::createScene();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question