mardi 30 octobre 2018

Bad: why my nested iterator class doesnt run a template method with specific class type?

i made a vector class(smiliar like std::vector class) with iterator and constiterator classes . im trying to make a special method for iterator class operator++() that will be run only with an iterator of type vector (person is a class with name and age) but it doesntt work , could anyone help me solve this problem ? /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class Iterator : public std::iterator { public: using value_type = Vector::value_type; using reference = Vector::reference; using pointer = Vector::pointer; using difference_type = Vector::difference_type; using iterator_category = std::forward_iterator_tag; private: pointer ptr; // double*

public:


    typedef iterator _Unchecked_type;

    size_t count() {
        return gesamt_counter;
    }

    Iterator() {
        ptr = nullptr;
    }
    Iterator(pointer x) : ptr{ x } {}
    reference operator*() const{
        return *ptr;
    }

    pointer operator->() const{

        return ptr;
    }

    bool operator==(const const_iterator& r) const { return static_cast<const_iterator>(*this) == r; }
    bool operator!=(const const_iterator& r) const { return static_cast<const_iterator>(*this) != r; }


    iterator operator++(int) { counter = 0; Iterator sub1 = *this; ++ptr; return sub1; }
    operator const_iterator() const { return const_iterator{ ptr }; }

    friend Vector::difference_type operator-(const Vector::iterator& l, const Vector::const_iterator& r)
    {
        return  static_cast<const_iterator>(l) - r;
    }


    iterator& operator++()
    { 
            ++ptr;      
        return *this;
    }

    template<>
    Vector<Person>::iterator& operator++()
    {
        ++ptr;
        ++ptr;
        return *this;
    }
};

Aucun commentaire:

Enregistrer un commentaire