#include
#include
using namespace std;
template<class T>
class ClassMyVec:public vector
{
public:
int it;
void CreatVector(int n)
{
T x;
for (int i = 0; i < n; i++)
{
cin >> x;
if (this->empty())//判断容器 谁调用函数就指向谁
this->push_back(x);
else if (x <= this->front)
this->insert(this->begin(), x);
else if (x >= this->back)
push_back(x);
else
{
vector::iterator it = begin(); //迭代器
while ((*it < x) && it != end())
it++;
insert(it, x); //在it位置插入x
}
}
}
void ShowVector() //输出向量
{
if (empty())
{
cout << "NULL" << endl;
return;
}
vector::iterator int it = begin();//迭代器输出向量
while (it != end())
{
cout << *it++ << ' ';
//it++;
}
for (int i = 0; i < size(); i++)
{
cout << this->at(i) << ' ';
cout << endl;
}
}
};
int main()
{
ClassMyVec<int>v;
v.CreatVector(10);
v.ShowVector();
return 0;
system("pause");
}
上面是我的代码,
下面是我的错误:
问题主要是出在迭代器使用语句那里,it。
问一下朋友们怎么解决谢谢了。