Jump to content
  • Advertisement
Sign in to follow this  
raptorstrike

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.

If you intended to correct an error in the post then please contact us.

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


Link to post
Share on other sites
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;
}

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!