template<typename T>
struct Vector {
class Iterator;
Vector &insert(Iterator it , T element)// HERE IS ERROR
{
arr_+it=element;
return *this;
}
private:
T* arr_=nullptr;
size_t size_;};
template <typename T>
class Vector<T>::Iterator
: public std::iterator<std::random_access_iterator_tag, T> {
public:
Iterator(T *ptr)
:ptr_{ptr}
{}
~Iterator() {
delete ptr_;
}
private:
T *ptr_;
};
I marked a spot where it gives me error. I gives me error only when I put Iterator type as ARGUMEN for function. I can put Iterator as return type, even if I put it as const Interator& it or just Iterator&it as function argument it doesn't give me error. Only if I put it as copy in funcion argument. And it says
Variable has incomplete type. I tried to copy that same code in Iterator class and it works fine, but my test.cpp needs it to be in Vector class
template < typename T >
struct Vector {
class Iterator ; // declaration
Vector& insert( Iterator iter, T element ) ; // declaration
};
template < typename T >
class Vector<T>::Iterator /* : public etc. */ { // definition
// ...
};
template < typename T >
Vector<T>& Vector<T>::insert( Vector<T>::Iterator iter, T element ) { // definition
// use iter ...
return *this ;
}