W
wangxiaohu
I am trying to write a class myVector based on std::vector and add
only a sort method. The sort method needs to access the array stored
in the base class using iterator. I have following draft code. However
it never compile. Can anyone take a look and tell me how to fix it?
Thanks!
#include <vector>
#include <iostream>
using namespace std;
template <typename T> class myVector : public vector<T>
{
public:
void Sort();
};
template <typename T> void Sort<T>::Sort()
{
if (this.size() < 2)
{
return;
}
vector<T>::iterator i;
for (i = this.begin(); i != this.end(); i++)
{
//rest part ignored....
}
}
only a sort method. The sort method needs to access the array stored
in the base class using iterator. I have following draft code. However
it never compile. Can anyone take a look and tell me how to fix it?
Thanks!
#include <vector>
#include <iostream>
using namespace std;
template <typename T> class myVector : public vector<T>
{
public:
void Sort();
};
template <typename T> void Sort<T>::Sort()
{
if (this.size() < 2)
{
return;
}
vector<T>::iterator i;
for (i = this.begin(); i != this.end(); i++)
{
//rest part ignored....
}
}