vector assignment problem*solved*
ok i have a function like this
int Map::Set_Equal(const char* SZ_FILENAME,vector<Tile*> *N_TList, vector<Event*> *N_EList)
{
ifstream fin;
fin.open(SZ_FILENAME);
for(int i = 0; i < 50; i++)
{
for(int j = 0; j < 50; j++)
{
fin >> A_Map[j];
};
};
Map_List.clear();
for(int l = 0; l < N_TList->size(); l++)
{
(Map_List)[l] = ((*N_TList)[l]);
};
Event_List.clear();
for(int k = 0; k < N_EList->size(); k++)
{
(Event_List)[k] = ((*N_EList)[k]);
};
fin.close();
};
this fills the member vector with an external vector (well at least it should) but its not and i dont know why, im calling the function, im imputing the function in the source with all valid paramters and Map_List isnt getting filled (hmm Event_List IS)
Map_List is a vector<Tile*>
N_TList is a vector<Tile*> *
(same thing with the event vectors but <Event*>)
thanks as always[smile]
ps. the functin gets called only once
[Edited by - raptorstrike on December 4, 2004 5:45:07 PM]
std::vector implements equal operator. You do not need to copy each element one by one. Just set it equal to the parameter:
Map_List = N_TList;
Oh, you must also pass your vector by reference instead of pointer. It's better that way.
int Map::Set_Equal( const char* SZ_FILENAME, vector<Tile*>& N_TList, vector<Event*>& N_EList )
{
Map_List = N_TList;
}
Map_List = N_TList;
Oh, you must also pass your vector by reference instead of pointer. It's better that way.
int Map::Set_Equal( const char* SZ_FILENAME, vector<Tile*>& N_TList, vector<Event*>& N_EList )
{
Map_List = N_TList;
}
or if you want another way of doing it:
dest.resize( src.size() );
std::copy( src.begin(), src.end(), dest.begin() );
dest.resize( src.size() );
std::copy( src.begin(), src.end(), dest.begin() );
woops scratch that the vector is now getting asigned but there is one last thing,
is accessing a vector<Tile*> elements with the [] operater valid?
because i have this line
if(A_Map->Map_List[A_Map->A_Map[tileY][tileX]]->Filled == true)
{
...
and my debugger leads me back too it so i cant help but think it has somthing to do with the way im acsessing the elements
A_Map is a int[][] tileY and tileX are ints and Map_List[A_Map[][]] HAS been defined
is accessing a vector<Tile*> elements with the [] operater valid?
because i have this line
if(A_Map->Map_List[A_Map->A_Map[tileY][tileX]]->Filled == true)
{
...
and my debugger leads me back too it so i cant help but think it has somthing to do with the way im acsessing the elements
A_Map is a int[][] tileY and tileX are ints and Map_List[A_Map[][]] HAS been defined
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement