I have a program to do for my data structures class and I have a problem that uses the "vector" library. Basically it wants me to write a template that reverses the elements in the vector object. Also it states the prototype it wants me to use... heres what I have so far.
#include <iostream>
#include <vector>
using namespace std;
template<class elemtype>
void reverseVector(vector<elemtype> &list)
{
elemtype b;
elemtype a;
a = list.back();
while (list.front() != a)
{
b=list.front();
list.push_back(b);
list.erase(0);
}
}
I constantly get this error:
c:\documents and settings\administrator.unimatrix001.000\my documents\c++\assign1.cpp(16) : error C2664: 'std::_Vector_iterator<_Ty,_Alloc> std::vector<_Ty>::erase(std::_Vector_iterator<_Ty,_Alloc>)' : cannot convert parameter 1 from 'int' to 'std::_Vector_iterator<_Ty,_Alloc>'
with
[
_Ty=int,
_Alloc=std::allocator<int>
]
No constructor could take the source type, or constructor overload resolution was ambiguous
I have no clue about this error. It says it can't convert from int to 'std::_Vector_iterator<_Ty,_Alloc>' when the erase parameter HAS to be of int. Their is no that in fact WOULDNT be an int. I simply do not get this....
#include <iostream>
#include <vector>
using namespace std;
template<class elemtype>
void reverseVector(vector<elemtype> &list)
{
elemtype b;
elemtype a;
a = list.back();
while (list.front() != a)
{
b=list.front();
list.push_back(b);
list.erase(0);
}
}
I constantly get this error:
c:\documents and settings\administrator.unimatrix001.000\my documents\c++\assign1.cpp(16) : error C2664: 'std::_Vector_iterator<_Ty,_Alloc> std::vector<_Ty>::erase(std::_Vector_iterator<_Ty,_Alloc>)' : cannot convert parameter 1 from 'int' to 'std::_Vector_iterator<_Ty,_Alloc>'
with
[
_Ty=int,
_Alloc=std::allocator<int>
]
No constructor could take the source type, or constructor overload resolution was ambiguous
I have no clue about this error. It says it can't convert from int to 'std::_Vector_iterator<_Ty,_Alloc>' when the erase parameter HAS to be of int. Their is no that in fact WOULDNT be an int. I simply do not get this....