2016-11-18 99 views
0

我使用的是Cocos 2d-x,我需要創建一個類的對象的向量,但是當我嘗試創建它們時出現類型錯誤像這樣:如何創建一個類的對象向量的向量

header 
Vector<Vector<Level*> > _stagesLevelsVec; 
//Here's the type Error when I try to create a Vector of Vectors of Objects of Class Level 
//Error: Invalid Type for cocos2d::Vector<T>! 
//Last output line: see reference to class template instantiation 'cocos2d::Vector<cocos2d::Vector<Level *>>' being compiled 

CPP

Level * level_0 = new Level; //I have to create an Object of Class Level 
level_0->setLevel(0); //I have to set a Property of the Object using a Method of the Class. 

Vector<Level *> allLevelsVec_0; //Here's the type Error when I try to create a Vector of Objects Level 
//Error: Invalid Type for cocos2d::Vector<T>! 
//Last output line: see reference to class template instantiation 'cocos2d::Vector<Level *>' being compiled 

allLevelsVec_0.pushBack(level_0); //I have to add the Object into the Vector 
_stagesLevelsVec.pushBack(allLevelsVec_0); //I have to add a Vector of Objets Level into a Vector 

//Then somewhere in code 

auto allLevelsVec = _stagesLevelsVec.at(0); // I have to get the Vector of Objects Level that I need 
auto level = allLevelsVec.at(0); //I have to get the Object Level 
auto levelId = level->getLevel(); //Finally I have to get the Property of level using a Method of the Class 

CCLOG("This is level: %i", levelId); //Output must be: This is level: 0.  

感謝在這個問題上的任何指引。問候。

+1

你是不是指'std :: vector'?從小寫字母(** v ** ector而不是** V ** ector)開始? –

+0

@AdrianColomitchi,我想它是'cocos2d :: Vector' – SingerOfTheFall

回答

2

doc,看來你嘗試禁聲明:

模板參數

筆 - 類型的元素。

T必須是指向cocos2d :: Ref後代對象類型的指針。由於我們已將cocos2d-x的內存管理模型集成到cocos2d :: Vector中,因此不允許其他數據類型或基元。 (自V3.0測試版)

您不能使用cocos2d::VectorT型。