2016-11-18 1 views
0

Ich verwende Cocos 2d-x und ich muss einen Vektor von Objekten einer Klasse erstellen, aber ich erhalte einen Type Error, wenn ich versuche, sie zu erstellen wie folgt aus:So erstellen Sie einen Vektor von Vektoren von Objekten einer Klasse

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.  

Vielen Dank für jede diesbezügliche Richtlinie. Schöne Grüße.

+1

Meintest du 'std :: vector'? Beginnend mit einem kleinen Buchstaben (** v ** ector im Gegensatz zu ** V ** ector)? –

+0

@AdrianColomitchi, ich nehme an, es ist 'cocos2d :: Vector' – SingerOfTheFall

Antwort

2

der doc Lesen, es scheint, dass Sie versuchen, eine verbotene Erklärung:

Template-Parameter

T - Die Art der Elemente.

T muss der Zeiger auf einen Coccos2d :: Ref-Nachkommen-Objekttyp sein. Es sind keine anderen Datentypen oder Primitive zulässig, da wir das Speicherverwaltungsmodell von cocos2d-x in cocos2d :: Vector integriert haben. (Seit v3.0 beta)

Sie können kein cocos2d::Vector als Typ T verwenden.

Verwandte Themen