vector.push_back(string) Doesn't work???

Feb 10, 2011 at 1:47pm
Hey there,

I got a problem with the push_back function of a vector to fill it with strings.

This is the code:
labelVector.push_back(labelString);

labelString works fine, but the labelVector just wouldn't get longer. It always has the size 1 and if I take it out of the class via a getter function

vector<string> openAssembler::getLabelVector(){
return labelVector;
}

it's size suddenly turns out to be 0.
Anybody has a clue what that could be?

Hope you guys can help me.

Thanks!
Last edited on Feb 10, 2011 at 4:42pm
Feb 10, 2011 at 9:42pm
Write a complete example that compiles so that we can see the problem duplicated that way.
Feb 11, 2011 at 7:19am
Does your implementation of push_back look like this?

1
2
3
4
5
template<typename T>
void Vector<T>::push_back(T value)
{
  return array[size++] = value;
}


Of course in your case the T would represent string.
Feb 11, 2011 at 10:37am
closed account (zb0S216C)
Of what type is labelString?

1
2
3
char *labelString;       // Is it this one?
char labelString[...];   // This one?
string labelString;      // Or this one? 
Last edited on Feb 11, 2011 at 10:39am
Topic archived. No new replies allowed.