std::vector of references

There are some possibilities: Store a vector of pointers (use if your vectors share ownership of the pointers): std::vector<std::shared_ptr<Foo>> vA, vB; Store a vector of wrapped references (use if the vectors do not share ownership of the pointers, and you know the object referenced are valid past the lifetime of the vectors): std::vector<std::reference_wrapper<Foo>> vA, vB; … Read more

iterator for 2d vector

Although your question is not very clear, I’m going to assume you mean a 2D vector to mean a vector of vectors: vector< vector<int> > vvi; Then you need to use two iterators to traverse it, the first the iterator of the “rows”, the second the iterators of the “columns” in that “row”: //assuming you … Read more

Declaring a 2D vector

std::vector has a fill constructor which creates a vector of n elements and fills with the value specified. a has the type std::vector<std::vector<int>> which means that it is a vector of a vector. Hence your default value to fill the vector is a vector itself, not an int. Therefore the second options is the correct … Read more

How to downsize std::vector? [duplicate]

Effective STL, by Scott Meyers, Item 17: Use the swap trick to trim excess capacity. vector<Person>(persons).swap(persons); After that, persons is “shrunk to fit”. This relies on the fact that vector‘s copy constructor allocates only as much as memory as needed for the elements being copied.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)