>> A pointer can otherwise become a vector<t>::iterator correct?
No, it cannot unless you are lucky enough for the implementation to have done it that way.
For simplicity, we'll assume a vector<int>. The erase function takes a vector<int>::iterator as its parameter:
Code:
vector<int>::iterator vector<int>::erase(vector<int>::iterator pos);
Let's say your vector implementation typedefs a class called VecIter as its iterator:
Code:
class VecIter
{
// ...
};
class vector
{
public:
typedef VecIter iterator;
// ...
};
So that means that erase takes a VecIter as its parameter:
Code:
VecIter vector<int>::erase(VecIter pos);
Now, you are trying to pass a pointer to int to this function that takes a VecIter. But an int pointer is not a VecIter, so it will fail.
I think what you are thinking of is the parameters taken by generic algorithms. These are templated types that are assumed to follow the traits of iterators. For example:
Code:
template <typename RandomAccessIter>
sort(RandomAccessIter beg, RandomAccessIter end);
The difference there is that sort takes any type as its parameters, and the template mechanism enforces that the type works as an iterator. However, the vector erase member function doesn't take any type, it takes a single specific type, whatever it typedef'd as iterator.
Passing a pointer will work if and only if the vector implementation uses a pointer as its iterator:
Code:
class vector
{
public:
typedef int* iterator;
// ...
};
But since that is not guaranteed, you cannot and should not rely on it. There are compilers that don't use pointers as iterators. The best example I can think of is debug build implementations that store extra information to aid in debugging.