I am a Java programmer and c++ is new to me. I have an issue with a pointer, in the code below i try to iterate over a list and push the pointer to the vector.
But when i iterate over the vector to see the value, i dont see all the values pushed in the vector. I just shows one value several time(size of the m_AgentInfoVector).
int vec_size = m_AgentInfoVector.size(); for (int agentIdx = 0; agentIdx < vec_size; agentIdx++) { DEBUG_Printf(Detail"====value in the vector is =[%s]", (m_AgentInfoVector[agentIdx])->msn); }
what can be the issue here, one thing i can think of is i am pushing same pointer to the vector. But i am not sure how to solve this? Help or suggestion will be really helpful.
int vec_size = m_AgentInfoVector.size();
for (int agentIdx = 0; agentIdx < vec_size; agentIdx++) {
DEBUG_Printf(Detail"====value in the vector is =[%s]", (m_AgentInfoVector[agentIdx])->msn);
}
thanks :coder777, i did realize that i always push same pointer to the vector. I can-not remove the "*" from my vector definition as other components in the code use it. Is there some other way i could resolve this??
Why do you use casting to char * (*finalNodeList_iter).c_str()? By default c_str() returns const char *
Also as already it was said you push_back the same object m_currentAgentInfo in the vector. What suggestings are you waiting?! It looks like ypu do not understand what you are doing. If you do not understand what you are doing how do we can help you?!
I am new to c++ and my first post here. I am tying to learn. Yes that casting is un-necessary.
After i have done the push_back of element on to the vector and then try to iterate over that vector, it just return last element pushed. The problem is that i always push the same pointer to the vector, how can i avoid it.
So for example i pushed values a, b and c into the vector and when i iterate over the vector to get the values, i just get "c" 3 times. Hope that makes things better.