nerdykid
August 7th, 2008, 01:56 PM
I have a struct called OBJECT and a vector called dynamic. the vector "dynamic" is a vector of the type OBJECT. My problem is that when I try to iterate through the vector, I cannot access the elements of OBJECT using the vector. For example:
vector<OBJECT> dynamic;
void LoadVector(OBJECT go[])
{
for(int i = 0; i <= 24; i++)
{
if(go[i].movable)
dynamic.push_back(go[i]);
}
}
void PullDown(OBJECT go[])
{
for(vector<OBJECT>::iterator iter = dynamic.begin(); iter < dynamic.end(); iter++)
{
++dynamic[iter].x; //This is where the problem is. Apparently it cannot access x
}
}
Is there any way to access an element from the vector (I have also tried ->)?
vector<OBJECT> dynamic;
void LoadVector(OBJECT go[])
{
for(int i = 0; i <= 24; i++)
{
if(go[i].movable)
dynamic.push_back(go[i]);
}
}
void PullDown(OBJECT go[])
{
for(vector<OBJECT>::iterator iter = dynamic.begin(); iter < dynamic.end(); iter++)
{
++dynamic[iter].x; //This is where the problem is. Apparently it cannot access x
}
}
Is there any way to access an element from the vector (I have also tried ->)?