vector assignment problem*solved*

Started by
4 comments, last by raptorstrike 19 years, 4 months ago
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]
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
Advertisement
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;
}
or if you want another way of doing it:

dest.resize( src.size() );
std::copy( src.begin(), src.end(), dest.begin() );
"I am a donut! Ask not how many tris/batch, but rather how many batches/frame!" -- Matthias Wloka & Richard Huddy, (GDC, DirectX 9 Performance)

http://www.silvermace.com/ -- My personal website
ok well i did what you guys said and it looks much better now but still no results
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
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
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie
ok never mind it was a big mistake on my part i was putting the function that called it BEFORE the intialization of SDL thanks a ton
____________________________"This just in, 9 out of 10 americans agree that 1 out of 10 americans will disagree with the other 9"- Colin Mochrie

This topic is closed to new replies.

Advertisement