Sign in to follow this  
raptorstrike

vector assignment problem*solved*

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[i][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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this