Answer the question
In order to leave comments, you need to log in
How to return a reference/pointer to an element of a vector?
We have a class (simplified):
class CUnit
{
public:
bool FindElement(const string& search, CElement& result);
private:
vector<CElement> mElements;
};
bool CUnit::FindElement(const string & search, CElement& result)
{
vector<CElement>::iterator it;
for (it = mElements.begin(); it != mElements.end(); it++)
{
if ( <тут проверка соответствие критерию> )
{
result = *it;
return true;
}
}
return false;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question