HELP! Accessing pointer elements of a vector!!!
Hi!
I’m having trouble knowing how to directly access pointer elements of a vector!
I have declared a vector named “_stationaryVerticeList”. I have declared this vector so that each element of this vector points to a vector of floats…..
-----------------------------------------------------------------------------------
Code:
typedef vector<float> VerticeList; //A vector of Vertice Lists
type def
vector<VerticeList*> _stationaryVerticeList; //A vector of Vertices
for this stationary
object
------------------------------------------------------------------------------------
Now, in turn, I have made 4 float vectors (each with 3 values pushed onto them), and added/pushed them onto the _stationaryVerticeList vector……
Code:
VerticeList* NewVerticeList_0 = new VerticeList();
NewVerticeList_0->push_back(45.5);
NewVerticeList_0->push_back(33.2);
NewVerticeList_0->push_back(77.8);
_stationaryVerticeList.push_back(NewVerticeList_0);
VerticeList* NewVerticeList_1 = new VerticeList();
NewVerticeList_1->push_back(23.7);
NewVerticeList_1->push_back(81.5);
NewVerticeList_1->push_back(67.2);
_stationaryVerticeList.push_back(NewVerticeList_1);
VerticeList* NewVerticeList_2 = new VerticeList();
NewVerticeList_2->push_back(54.2);
NewVerticeList_2->push_back(91.2);
NewVerticeList_2->push_back(12.9);
_stationaryVerticeList.push_back(NewVerticeList_2);
VerticeList* NewVerticeList_3 = new VerticeList();
NewVerticeList_3->push_back(14.2);
NewVerticeList_3->push_back(61.8);
NewVerticeList_3->push_back(19.9);
_stationaryVerticeList.push_back(NewVerticeList_3);
------------------------------------------------------------------------------
Now, I need to know how I can directly access one of these vertice values through the _stationaryVerticeList vector! For example, let’s say that I wanted to access the second value from the third list added to the _stationaryVerticeList vector (it should equal 91.2) – how would I do this? ANY help would be GREATLY appreciated!!!!!!
//---------Side Note! -----//
I know the data is being read in properly, because I’ve looped though the _stationaryVerticeList vector using …
Code:
for(vector<VerticeList*>::iterator it1 = _stationaryVerticeList.begin(); it1 != _stationaryVerticeList.end(); it1++)
{
for(vector<GLfloat>::iterator it2 = (*it1)->begin(); it2 != (*it1)->end(); it2++)
{
cout << "*It2 is " << (*it2) << endl;
}
}
…But I need to know how to directly access the values without having to go through this elaborate looping process!
//------End of side note! -------//