I am learning C ++ STL using this resource: http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=standardTemplateLibrary
The following function is specified here for accessing array elements:
template<typename T> void reversearr(T *begin, T *end) {
if(begin != end)
{
end--;
if(begin != end) {
while(true) {
swap(*begin, *end);
begin++;
if(begin == end) {
break;
}
end--;
if(begin == end) {
break;
}
}
}
}
}
It works with system types of arrays, such as:
int arr[]={1,2,3,4,5}
reversearr(arr,arr+5);
But it gives the following compiler error:
"Iterator02_ReverseIterators.cpp: 39: 32: error: there is no corresponding function to call 'reverseearr (std :: vector :: iterator, std :: vector :: iterator)'"
if i use this code:
vector<int> v;
reversearr(v.begin(),v.end());
How to write similar functions so that they can work as iterators?
source
share