c++,vector,containers,push-back
If you want to push_back into the vector returned by map[N], just use: //assuming std::map<int, std::vector<std::string>> my_map; int N; std::string my_string; my_map[N].push_back(my_string); ...
You don't show all the code, but I think the issue is that you use push_back to add entries to the end of the vector, but you instantiated the vector with size nombrePoint, which will cause it to create nombrePoint values that are default initialized. You then push another nombrePoint...
c++,object,vector,push-back,c2664
The vector is expecting a pointer to an object whereas the vPB you are pushing back is not a pointer to an object but rather the object itself. The minimum you can do to fix this is: NV* vPB = new NV(); vPB->name = namE; ... and similarly for all...
With a compiler that supports the C++11 standard you can use emplace_back, like this: vector <Book> books; books.emplace_back("a", "Jim John", 1000); books.emplace_back("b", "Jim John", 1001); books.emplace_back("c", "Billy Bill", 1002); books.emplace_back("d", "Greg Lumburge", 1003); books.emplace_back("e", "Dallas Orange", 1004); books.emplace_back("f", "Old McDonald", 1005); But easier still, with C++11, is to just list...
If you do not have virtual destructor in your Node class, deleting your Directory objects through base class pointer is undefined behaviour. Your Directory class' s destructor won't be called, also the destructor of the contained vector. This might cause the memory leak.
c++11,move,encapsulation,rvalue-reference,push-back
Yes, you need std::move here, but you could also use emplace_back here: template <typename T> void Queue<T>::push( T && val ) { c.emplace_back( std::move(val) ); } ...
There is nothing in the code shown that would make objects be inserted twice, so it comes down to some old-fashioned debugging skills. For a start, change the loader function to be something like: bool Level1::LoadContent() { std::cout << "Enter LoadContent with size " << SpriteList2.size() << '\n'; Sprite1 Sprite_1({0.0f,...
There are a few problems with your code: you are pre-allocating the size() of each std::vector, which means you are pre-filling them with blank values. Then you are reading into those existing elements (which is fine) and also push_back()ing what you have already stored (which is wrong). So, either stop...
In the second case, you are indexing from firstHalfSize. You need to cout the values starting from index 0. For example: cout << "v: " << secondHalf[i-firstHalfSize] << endl; ...
c++,linked-list,syntax-error,push-back
When the list is empty, push only a single item and return if(head == nullptr) // using nullptr instead of NULL { tail = head = new IntNode(ne); head->next = nullptr; return; } Because in case of 1st time push, the item would be inserted twice....
c++,memory-management,vector,push-back
I invite you over to my house, giving you my address which you hastily note down on paper. You come over and see that my house has green walls. The next day, you copy the address into your phone's address book for safekeeping. A few months later, I repaint...
First, you need to change TeamS to have a list of strings for team members, not just one string. struct TeamS { int ID_NUM; std::vector<string> team_members; }; In the function to initialize teamV: void Initialize(vector <TeamS> & TeamV, const int Id[], const string m[][MEMBERS], int arraysize) { cout <<...
"why is this happening and how do I make it so that the entire strings (including the spaces) get stored?" To get more than a single word from the input you should use std::getline(cin,n); instead of std::cin >> n; White spaces are used as delimiters by default, so each...
This looks like address space exhaustion. If you are compiling for a 32-bit target, you will generally be limited to 2 GiB of user-mode accessible address space per process, or maybe 3 GiB on some platforms. (The remainder is reserved for kernel-mode mappings shared between processes) If you are running...
qt,containers,copy-constructor,push-back
In the case of QObject derived objects, you have to use dynamic allocation and just put pointers in the container, because such objects have unique identities and as such are prohibited from copying. In that case only the pointer is copied around, which is just an integer, the copying of...
Your first while loop reads until end-of-file... after end of file your stream state has EOF bit set, which is why that loop exits. It's also why the next attempt to cin >> Uword exits without doing anything. If you'd written something like... if (!(cin >> UWord)) { std::cerr <<...
Why do you have to create a new Vector<T>? Just create a new array: template <class T> void Vector <T> :: push_back(const T & number) { if(numItems == capacity) { capacity *= 2; T* newData = new T[capacity]; std::copy(data, data + numItems, newData); delete[] data; data = newData; } data[numItems++]...