I just has a vector like that
vector<User*> users;
I know it is not a good programming style…
now I have a function
vector<User> getAllUser(void)
{
}
What I had tried is
vector<User> getAllUser(void)
{
vector<User> result;
for (vector<User*>::iterator it = users.begin(); it != users.end(); it++)
{
result.push_back(**it);
}
return result;
}
But it didn’t work.
Could someone to help me? Thankyou very much. I am just a beginner to STL
You code should work, but you made a typo:
push_bachis not a declared function forstd::vector, so I’m assuming that’s where the error lies. I would recommend you get a decent compiler, which should point this error out to you right away, without having to go through stackoverflow.To fix, use the proper method name,
push_backinstead: