Public Group

# vector assignment problem*solved*

This topic is 5092 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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]

##### Share on other sites
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;
}

##### Share on other sites
or if you want another way of doing it:

dest.resize( src.size() );
std::copy( src.begin(), src.end(), dest.begin() );

##### Share on other sites
ok well i did what you guys said and it looks much better now but still no results

##### Share on other sites
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

##### Share on other sites
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

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633287
• Total Posts
3011217
• ### Who's Online (See full list)

There are no registered users currently online

×