quote:Original post by edwinnieYou should get yourself familiar with it; it's really handy. You must have an #include <vector>. Some poeple also use using namespace std; so they don't have to qualify the namespace (std::xxx), but I think it is good to be explicit.
i must say, i am not realli gd at STL yet,
so i kept getting errors like "vector is not a member of 'std'"?
quote:hmm...i might have noticed:I'm not sure what you are asking about here. The first one you could use like this:
void GetCrystals(std::vector<Crystal *> &crystal_vector);
std::vector<Crystal *> GetCrystals(void);
or
std::vector Player::GetCrystals(void);
hmm... return type is a std::vector? or std::vector<Crystal*>?
std::vector<Crystal *> crystal_list;
player.GetCrystals(crystal_list); // function will "build" your crystal_list
play_area.Generate(crystal_list);
The second return the whole vector object, and could be used like this:
play_area.Generate(player.GetCrystals());
Your alternate approach won't work; you need to specify a type which the vector should hold. In this case Crystal *.
quote:and how come function arguments are different? one is void and the other is std::vector<Crystal*> &crystal_vector?Alternate approaches. You can either tell the function where to store the pointers, or let the function return them. The latter is cleaner , but is less efficient. In the former case you only need to pass a reference (a pointer) to the function which don't have to return anything, while the latter needs to return an object that is possibly 4 times the size of a pointer.
[edited by - CWizard on May 5, 2003 9:25:17 AM]