Reputation: 3071
I want to know how I can define vector variables to save output of this code in vector?
/*what should be here?*/=agent.GetInfoState().GetPositionInfo().GetCloseTeammateToTeammate(2);
GetcloseTeammateToTeammate
is defined as:
const std::vector<Unum> & GetCloseTeammateToTeammate(Unum i)
{
Assert(i > 0); return GetCloseTeammateToPlayer(i); }
Upvotes: 0
Views: 229
Reputation: 208456
There are two different options there, depending on what you actually want. If you only intend to do some processing on the given vector in the short term, (and assuming single threaded execution and a couple other considerations) you can just keep the reference:
std::vector<Unum> const & v = agent.GetInfoState().GetPositionInfo().GetCloseTeammateToTeammate(2);
for ( std::vector<Unum>::const_iterator it = v.begin(), end = v.end(); it != end; ++it )
{
// do something
}
If what you want is to save a copy of the vector so that at a later time you can check for changes, or you want to use the vector as it is now without any later changes (note that this is not entailing thread safety!), just copy it:
std::vector<Unum> copy = agent.GetInfoState().GetPositionInfo().GetCloseTeammateToTeammate(2);
Upvotes: 1
Reputation: 59841
GetCloseTeammateToTeammate
returns a reference to a constant vector.
Simply use:
const std::vector<Unum>& x = agent.GetInfoState().GetPositionInfo().GetCloseTeammateToTeammate(2);
to get the reference. Note that you can only call const member functions of vector.
To get a copy of the vector, do:
std::vector<Unum> x = agent.GetInfoState().GetPositionInfo().GetCloseTeammateToTeammate(2);
Only copy if you really need to.
Upvotes: 5
Reputation: 272802
I must be missing something here. Is it not simply this:
const std::vector<Unum> &my_vector = agent.GetInfoState().GetPositionInfo().GetCloseTeammateToTeammate(2);
Upvotes: 2