vector and const

I’ve added a few lines to your code. That’s sufficient to make it clear why this is disallowed: void f(vector<const T*>& p) { static const T ct; p.push_back(&ct); // adds a const T* to nonConstVec ! } int main() { vector<T*> nonConstVec; f(nonConstVec); nonConstVec.back()->nonConstFunction(); }

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

error for hash function of pair of ints

Unfortunately, this program has undefined behavior. C++11 ยง17.6.4.2.1: A program may add a template specialization for any standard library template to namespace std only if the declaration depends on a user-defined type and the specialization meets the standard library requirements for the original template and is not explicitly prohibited. hash<pair<int,int>> depends on primitive and standard … Read more