Теперь я столкнулся с огромной проблемой. проблема. Рассмотрим следующий фрагмент:
Код: Выделить всё
custom_vector::iterator it_start = container.begin(), it_end = container.end();
custom_vector other_container(it_start, --(--it_end));
Код: Выделить всё
template
class bidirectional_iterator : public forward_iterator
{
// ...
public:
/* Decrement Operators */
bidirectional_iterator &operator--() { /* code */ }
bidirectional_iterator operator--(int) { /* code */ }
// ...
}
Код: Выделить всё
custom_vector other_container(it_start, --(--it_end));
Код: Выделить всё
error: no matching constructor for initialization of 'custom_vector'
custom_vector other_container(it_start, --(--it_end));
^ ~~~~~~~~~~~~~~~~~~~~~~
candidate constructor not viable: no known conversion from 'custom_vector::iterator' (aka 'random_access_iterator') to 'custom_vector::size_type' (aka 'unsigned long') for 1st argument
explicit custom_vector(size_type n, const value_type &val = value_type(), const allocator_type &alloc = allocator_type()) : _capacity(n), _alloc(alloc)
^
note: candidate template ignored: deduced conflicting types for parameter 'InputIterator' ('random_access_iterator' vs. 'bidirectional_iterator')
custom_vector(InputIterator first, InputIterator last, const allocator_type &alloc = allocator_type(),
^
note: candidate constructor not viable: allows at most single argument 'alloc', but 2 arguments were provided
explicit custom_vector(const allocator_type &alloc = allocator_type()) : _capacity(), _alloc(alloc), _content() {}
^
note: candidate constructor not viable: requires single argument 'x', but 2 arguments were provided
custom_vector(const custom_vector &x) : _capacity(x.capacity()), _alloc(x.get_allocator()), _content()
^
1 error generated.
- Правильна ли моя реализация Iterator с наследованием? Имеет ли смысл придерживаться этой реализации или было бы лучше просто реализовать для каждого контейнера определенный итератор?
- Есть ли способ реализовать «конвертер итератора», который автоматически преобразует пример моего двунаправленного_итератора в случайный_итератор_доступа, когда это необходимо?
Подробнее здесь: https://stackoverflow.com/questions/721 ... nheritance