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
1
vote
1 answer

Initializing multi-dimensional std::vector without knowing dimensions in advance

Context: I have a class, E (think of it as an organism) and a struct, H (a single cell within the organism). The goal is to estimate some characterizing parameters of E. H has some properties that are stored in multi-dimensional matrices. But, the…
kei2e
  • 13
  • 3
1
vote
1 answer

Vector element Destructor not called with reserve

I have this class: class aa { public: int i = 0; ~aa(){ std::cout << "killin in the name of" << std::endl; } }; And I want to make a vector of this class. First I thought o reserving the needed size: int main() { std::vector
Ivan
  • 1,352
  • 2
  • 13
  • 31
1
vote
2 answers

Why this code does allow to push_back unique_ptr do vector?

so I thought adding unique to vector shouldn't work. Why does it work for the below code? Is it cause by not setting copy ctor as "deleted"?? #include #include #include class Test { public: int i =…
wlodek14a
  • 63
  • 4
1
vote
1 answer

Mashed-up data in string vector

I've been trying to fix this for ages, I've got a program that takes in a random word from a supplied dictionary (txt file), and then adds this word to a vector of strings. The randomWord() function works as intended, but the getWords() seems to…
offshore
  • 11
  • 3
1
vote
1 answer

error: no matching function for call to vector::push_back

I'm new to C++ and am trying to use pushback function to store food orders in a vector object so that the food orders can be compiled and repeated back later. But I get the error: no matching function for call to…
ahmadalibin
  • 133
  • 8
1
vote
1 answer

Why can we push_back a subvector defined only with range?

Say I have a vector a = {1,2,3,4,5,6} and vector>b . Why can we write b.push_back({a.begin() + 1, a.begin() + 4}); and end up with b = {{2345}}? I simplified this from a portion of code, so if this specific bunch of code doesn't…
Blue
  • 29
  • 2
1
vote
1 answer

segmentation fault when push_back or erase on std::list

Some pieces of my code crash randomly when call push_back or erase on std::list, the code is in a long time runing service . I removed the unimportant part and just keep the most relevant. std::list pendingSync; size_t…
zhuo.quan
  • 63
  • 7
1
vote
1 answer

Confusion on push_back interaction with pair

I have no error message instead I only have unexpected behavior. double get_optimal_value(int capacity, vector weights, vector values) { int n = weights.size(); vector> valuePerWeight(n); pair x; …
1
vote
1 answer

push_back in vector showing error

I have inserted a string, i want each character to be separately be inserted in the vector string. On using the push_back function i get the following error: error: no matching function for call to 'std::vector
1
vote
1 answer

Can I implement a push_back method for linked list in that way?

I've already been doing push_back methods for link lists like that: #include using namespace std; class Node{ public: int data; Node* next; Node(int data, Node* next = nullptr){ this->data = data; this->next…
dimm
  • 51
  • 1
  • 7
1
vote
1 answer

I can't push_back a unique_ptr after passed it into a function

I'm working on my little project about pointers, I ran into problem when I was trying to push a unique_ptr to a derived class, to a vector of unique_ptr to base class. It keeps saying that I'm "attempting to reference to a deleted function". I tried…
Duc Nguyen
  • 11
  • 1
1
vote
1 answer

clang tidy complains about push_back into vector in a loop

Here's my code(works fine), and the complaint of IDE: I tried setting vector size with vector result(tmp.size()); but after that, result will contain tmp.size() amount of empty strings in the front, and I don't wan't to use insert. Is…
gone
  • 823
  • 8
  • 21
1
vote
1 answer

How can I add an item to the structure with vector elements?

I would like to add the peak position of a vector and the peak number but I can't find a way to add the elements and then return it, or write it on console. #include #include using namespace std; struct PeakData { …
Pilv
  • 61
  • 7
1
vote
1 answer

How to create an emplace_back method?

I´m creating a custom ArrayList/Vector class and I´m having troubles creating an emplace_back function. How can I create arguments that are the same as the constructor of the "value_type class" of the ArrayList ?
1
vote
2 answers

Pushing a string to a private member vector

I have a std::vector tileSet_ as a member variable of a class. In the constructor of said class I call the function void MapWindow::shuffleTiles() const { std::vector> tileAmounts = { {"a", 2},…
sesodesa
  • 1,473
  • 2
  • 15
  • 24