Hello,
First, let me state that I have solved the issue that was giving me the VC++ debug assertion: "Expression: vector iterators incompatible". It's just that I'm not exactly how my change made a difference.
I have a 2-d array template class which as its only member has a vector-of-vectors. An abbreviated version is shown below:
The problem occurred in the implementation of the copy constructor body:Code:template <class T> class vector2 { protected: vector<vector<T> > elements; public: vector2(); vector2(unsigned rows, unsigned columns); vector2(unsigned rows, unsigned columns, const T& value); vector2(const vector2<T>& other); //Overloaded operators vector2<T>& operator=(const vector2<T>& other); vector<T>& operator[] (unsigned index); vector<T> operator[] (unsigned index) const; // ...other member methods... };
...which usually worked, but I subsequently changed it to:Code:template <class T> vector2<T>::vector2(const vector2<T>& other) : elements(other.elements) { }
...and VC++ no longer asserted. Thus, it appears the incompatible vector iterators has something to do copy-constructing a std::vector-of-std::vectors, rather than using the assignment operator. Can anyone explain why exactly this occurs? I'm not a newbie but I'm also not an expert, so this might be a little beyond my current understanding. Normally, using the copy constructor works just fine - each vector-of-vector elements are always copied as I expect. It's just this specific assertion that I've never run into before.Code:template <class T> vector2<T>::vector2(const vector2<T>& other) { elements = other.elements; }
Thanks in advance!



LinkBack URL
About LinkBacks



