Я пытаюсь скомпилировать обратный итератор, но мои попытки сделать это дают ужасный беспорядок. Минимальный пример кода ...Обратный итератор не компилируется
#include <iostream>
#include <vector>
#include <algorithm>
class frag {
public:
void print (void) const;
private:
std::vector<int> a;
};
void frag::print (void) const
{
for (std::vector<int>::reverse_iterator iter = a.begin();
iter != a.end();
++iter) {
std::cout << *iter << std::endl;
}
}
и пытается скомпилировать производит следующее ...
In file included from /usr/include/c++/4.4/bits/stl_algobase.h:69,
from /usr/include/c++/4.4/bits/char_traits.h:41,
from /usr/include/c++/4.4/ios:41,
from /usr/include/c++/4.4/ostream:40,
from /usr/include/c++/4.4/iostream:40,
from frag.cpp:1:
/usr/include/c++/4.4/bits/stl_iterator.h: In constructor ‘std::reverse_iterator<_Iterator>::reverse_iterator(const std::reverse_iterator<_Iter>&) [with _Iter = __gnu_cxx::__normal_iterator<const int*, std::vector<int, std::allocator<int> > >, _Iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >]’:
frag.cpp:14: instantiated from here
/usr/include/c++/4.4/bits/stl_iterator.h:134: error: no matching function for call to ‘__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >::__normal_iterator(__gnu_cxx::__normal_iterator<const int*, std::vector<int, std::allocator<int> > >)’
/usr/include/c++/4.4/bits/stl_iterator.h:686: note: candidates are: __gnu_cxx::__normal_iterator<_Iterator, _Container>::__normal_iterator(const _Iterator&) [with _Iterator = int*, _Container = std::vector<int, std::allocator<int> >]
/usr/include/c++/4.4/bits/stl_iterator.h:683: note: __gnu_cxx::__normal_iterator<_Iterator, _Container>::__normal_iterator() [with _Iterator = int*, _Container = std::vector<int, std::allocator<int> >]
/usr/include/c++/4.4/bits/stl_iterator.h:669: note: __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >::__normal_iterator(const __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >&)
Был вопрос по этому вопросу вчера, но я не думаю, что это это то же самое, что и не шаблон. Если вектор объявлен аналогичным образом локально, он вполне доволен. (g ++ на Ubuntu 10.4).
Кто-нибудь знает, что я должен делать?
dang, пару минут раньше :( – rubenvb
@rubenvb: Хотя моя первая попытка только заметила одну проблему, отредактированную отчаянно, чтобы обновить вторую проблему. –
: D некоторые вопросы просто привлекают толпу, не так ли? – rubenvb