I've updated to a newer C++ compiler (going from Visual C++ 6.0 to Visual C++ 2015) and I am working on converting a Vector template class to be compatible. One error I am encountering involves the vector::erase method and the input type.
Template class snippet:
template<class Type> class Vector { public: typedef Type* iterator; typedef const Type* const_iterator; ... iterator erase( const_iterator iBegin ); iterator erase( const_iterator iBegin, iEnd ); private: VectorImpl<Type>* m_pImpl; }; ... template <typename Type> typename Vector<Type>::iterator Vector<Type>::erase( typename Vector<Type>::const_iterator iBegin ) { return m_pImpl->erase( iBegin ); };...
Error:
C2440: 'initializing': cannot convert from 'const int*' to 'std::_Vector_const_iterator>>'
I was able to convert a std::vector iterator to an int* by dereferencing the iterator but I'm not sure how to do the inverse:
template <typename Type> typename Vector<Type>::const_iterator Vector<Type>::begin() { Vector<Type>::const_iterator begin = &(*m_pImpl->begin()); return begin; }; Q: Is it possible to convert a const int* to a std::vector const_iterator?
const_iteratorthat points to something you'll need another iterator, or the container itself....'s are clearly suspect. Post the smallest code sample that you can create that shows the problem. For example, although your question mentionsstd::vector const_iterator, there is nothing in this code that mentionsstd::vectoror its iterators.std::vector?