VC 模板问题!!!在线等 高手进

#include<iostream>usingnamespacestd;template<typenameT>classvector{private:T*p;intlen... #include<iostream>
using namespace std;
template <typename T>
class vector
{

private:
T *p;
int length;
public:
vector(int n=0);
vector(int n,T a);
vector(vector <T> & b);
friend T& operator[](vector &,int);
vector& operator=(vector <T> &aa);
friend bool operator ==(vector <T> &aa,vector<T> &bb);
T *begin();
T *end();
void insert(T *pp,T x);
bool erase(T *x);
bool erase (T *x,T *y);
int MyLength()
{
return length;
}
};

template <typename T>
T& operator[](vector &c,int ii)
{
return c[ii];
}

template <typename T>
vector<T>::vector(int n = 0)
{
length=n;
p=new T[length];
}

template <typename T>
vector<T>::vector(int n, T a)
{
length=n;
p=new T[length];
for(int i=0;i<length;i++)
p[i]=a;
}

template <typename T>
vector<T>::vector(vector <T> & b)
{
p=new T[b.length];
for(int i=0;i<b.length;i++)
p[i]=b[i];
}

template <typename T>
vector& vector<T>::operator=(vector <T> &aa)
{
p=new T[aa.length];
for(int i=0;i<aa.length;i++)
p[i]=aa[i];
return *this;
}

template <typename T>
bool operator==(vector <T>&aa,vector<T> &bb)
{
if(aa.length!=bb.length)
return false;
else
{ for(int i=0;i<aa.length;i++)
{if(aa[i]==bb[i])
return true;
else
return false;
}
}
}

template <typename T>
T * vector<T>::begin()
{
return p;
}

template <typename T>
T* vector<T>::end()
{
return p[length];
}

template <typename T>
void vector<T>::insert(T *pp,T x)
{
for(int j=length;j>pp-vector::begin();j--)
p[j+1]=p[j];
p[j]=x;
length++;
}

template <typename T>
bool vector<T>::erase(T *x)
{
if(x-vector::begin()<0||x-vector::begin())
return false;
else
{
for(int i=x-vector::begin();i<length;i++)
p[i]=p[i+1];
length--;
return true;
}
}
template <typename T>
bool vector<T>::erase (T *x,T *y)
{
if(x-vector::begin()<0||y-vector::begin()>0)
return false;
else
{
for(int i=x-vector::begin();i<length-((y-vector::begin())-(x-vector::begin()));i++)
p[i]=p[i+(y-vector::begin())-(x-vector::begin())];
length=length-((y-vector::begin())-(x-vector::begin()));
return ture;
}
}

int main()
{
return 0;
}

帮我调试下啊 环境是VS2005
答的好一定加分
展开
 我来答
wanfustudio
2009-05-12 · TA获得超过1万个赞
知道大有可为答主
回答量:5513
采纳率:100%
帮助的人:3753万
展开全部
#include<iostream>
using namespace std;

template <typename T>
class Vector
{
private:
T *p;
int length;
public:
Vector(int n=0);
Vector(int n,T a);
Vector(Vector <T> & b);
T& operator [](int);
Vector<T>& operator = (Vector <T> &aa);
friend bool operator ==(Vector <T> &aa,Vector<T> &bb);
T *begin();
T *end();
void insert(T *pp,T x);
bool erase(T *x);
bool erase (T *x,T *y);
int MyLength()
{
return length;
}
};

template <typename T>
T& Vector<T>::operator[](int ii)
{
return c[ii];
}

template <typename T>
Vector<T>::Vector(int n)
{
length=n;
p=new T[length];
}

template <typename T>
Vector<T>::Vector(int n, T a)
{
length=n;
p=new T[length];
for(int i=0;i<length;i++)
p[i]=a;
}

template <typename T>
Vector<T>::Vector(Vector <T> & b)
{
p=new T[b.length];
for(int i=0;i<b.length;i++)
p[i]=b[i];
}

template <typename T>
Vector<T>& Vector<T>::operator=(Vector <T> &aa)
{
p=new T[aa.length];
for(int i=0;i<aa.length;i++)
p[i]=aa[i];
return *this;
}

template <typename T>
bool operator==(Vector <T>&aa,Vector<T> &bb)
{
if(aa.length!=bb.length)
return false;
else
{ for(int i=0;i<aa.length;i++)
{if(aa[i]==bb[i])
return true;
else
return false;
}
}
}

template <typename T>
T * Vector<T>::begin()
{
return p;
}

template <typename T>
T* Vector<T>::end()
{
return p[length];
}

template <typename T>
void Vector<T>::insert(T *pp,T x)
{
for(int j=length;j>pp-Vector::begin();j--)
p[j+1]=p[j];
p[j]=x;
length++;
}

template <typename T>
bool Vector<T>::erase(T *x)
{
if(x-Vector::begin()<0||x-Vector::begin())
return false;
else
{
for(int i=x-Vector::begin();i<length;i++)
p[i]=p[i+1];
length--;
return true;
}
}
template <typename T>
bool Vector<T>::erase (T *x,T *y)
{
if(x-Vector::begin()<0||y-Vector::begin()>0)
return false;
else
{
for(int i=x-Vector::begin();i<length-((y-Vector::begin())-(x-Vector::begin()));i++)
p[i]=p[i+(y-Vector::begin())-(x-Vector::begin())];
length=length-((y-Vector::begin())-(x-Vector::begin()));
return ture;
}
}

int main()
{
return 0;
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式