Questions tagged [push-back]

is the action of adding an element at the end of a container.

push-back is the action of adding an element at the end of a container.

420 questions
4
votes
1 answer

Vector pointer and push_back()

If I have void f(vector *vo) { } And I pass the address of a vector to f vector vo; f(&vo); How would I use push_back() to add to the vector?
el_pup_le
  • 11,711
  • 26
  • 85
  • 142
4
votes
5 answers

Why is it considered bad style to use the index operator on a vector in C++?

I am working on a program that uses vectors. So the first thing I did was declare my vector. std::vector x; x.reserve(10) (BTW, is this also considered bad practice? Should I just type std::vector x(10)?) Then I proceeded to assign…
Nerdrigo
  • 308
  • 1
  • 5
  • 14
4
votes
4 answers

Does push_back() always increase a vector's size?

I have a piece of code which creates a std::vector with a known size: std::vector vectorOfTs(n); Does calling push_back increase the size to n+1? vectorOfTs.push_back(T());
tunnuz
  • 23,338
  • 31
  • 90
  • 128
4
votes
6 answers

Vector push_back Access Violation

This is probably a silly error, but it's driving me nuts trying to fix it. I have a struct: struct MarkerData { int pattId; unsigned short boneId; Ogre::Matrix4 transToBone; Ogre::Vector3 translation; Ogre::Quaternion orientation; …
Jack
  • 63
  • 1
  • 1
  • 4
4
votes
3 answers

C++ Multiple Struct Vectors Error

I am trying to make two different vectors containing custom structures but when I try to add elements to the vectors it works for the "deck" vector but throws an error of the "players" vector. I am new to C++ and cannot figure out what is…
keerl
  • 116
  • 1
  • 11
4
votes
2 answers

Pushing back an object in a vector without the object

I know that the correct way of push back an object in a vector is to declare an object of the same class and pass it by value as argument of method push_back. i.e. something like class MyClass{ int a; int b; int c; }; int main(){ …
gvgramazio
  • 1,115
  • 3
  • 13
  • 30
4
votes
1 answer

Vector push_back only if enough memory is available

I am currently building a code that is dealing with massive amounts of memory using the vector class, dynamically. The code is building up the vector with push_back, where it is important to notice that the vector is 2 dimensional, representing the…
bluecore
  • 237
  • 2
  • 12
4
votes
1 answer

std::vector push_back() semantics

I understand that push_back in an std::vector places a copy of the object passed as argument at the end. Let's consider this simple example class Foo { public: Foo(int i=-1) :i_(i) {std::cout << "Foo:" << i_ << std::endl;} Foo(const Foo& rhs) …
4
votes
2 answers

Why can't I push a const pointer to std::vector?

Consider the piece of code: class T; void constructVector(const T* item) { std::vector v; v.push_back(item); } I get an error with MSVC 2010 compiler: error: C2664: 'void std::vector<_Ty>::push_back(_Ty &&)' : cannot convert parameter…
Violet Giraffe
  • 32,368
  • 48
  • 194
  • 335
4
votes
2 answers

push_back versus operator[] assignment in c++ vectors

can someone please explain to me in detail why the following code for vectorY will do the assignment but the size of VecY is zero? Also, the begin and end iterators are stuck at the first node. It seems that reserve only works with push back and…
bjackfly
  • 3,236
  • 2
  • 25
  • 38
4
votes
5 answers

push back for the map container

we got this map : std::map values; would this function be the same as the push_back function of a Vector : void PushBack(int value) { values[values.size()] = value; } since size returns the size of the container I thought it would be…
user2140285
  • 173
  • 2
  • 3
  • 12
4
votes
3 answers

STL vector push_back() memory double free

Possible Duplicate: What is The Rule of Three? I have the a problem of the double freeing of memory in the following program. The debugger shows that the issue is in the push_back() function. Class A: class A { public: A(int x); …
Alex
  • 9,891
  • 11
  • 53
  • 87
4
votes
1 answer

GDB wrong values for vector.size()

A simple vector.push_back() causes some error in my code: #include using namespace std; int main(int argc, const char *argv[]) { vector stack; stack.push_back(1); stack.push_back(1); //stack.size() becomes 467369971…
neuron
  • 1,896
  • 1
  • 19
  • 24
3
votes
1 answer

C++ vector of set gives segmentation fault after performing push_back

I have created a vector of sets in my program, and I need to go through each of the sets. In case a specific element is found in the set, I need to add a new set to the vector. However, this gives me a segmentation fault as soon as my array's…
Arani
  • 400
  • 6
  • 21
3
votes
3 answers

Push_back 1D Vector as Row into 2D Vector Array

I'm trying to define the values of a 'row' or 1D vector and then push_back that row into a 2D vector. I've tried a couple different things that don't throw errors but also don't seem to work. Code below: #include #include using…
ProGirlXOXO
  • 2,170
  • 6
  • 25
  • 47
1 2
3
27 28