读书人

新人(有关问题可能有点小白)

发布时间: 2013-04-20 19:43:01 作者: rapoo

新人求救(问题可能有点小白)
#include<iostream>
using namespace std;
class xl
{private:
public:
int *v;
int len;
xl (int mun);
xl (int * ,int);
xl operator+(xl);
xl operator-(xl);
xl operator*(xl);
friend ostream & operator << (ostream & output,const xl &);
friend istream & operator >> (istream & intput,const xl &);
};
xl::xl(int mun)
{
if(mun <= 0 || mun > 100)
{cout<<"fail\n";
exit(0);
}
v=new int[mun];
for(int i=0;i<mun;i++)v[i]=0;
len=mun;
}
xl::xl (int * A,int mun)
{
if(mun <= 0 || mun > 100)
{cout<<"fail\n";
exit(0);
}
v=new int[mun];
len=mun;
for(int i=0;i<mun;i++)v[i]=A[i];
}
ostream & operator<<(ostream & output,xl & a)
{
for(int i=0;i<a.len;i++)
output << a.v[i]<<"";
return output;
}
istream & operator>>(istream & intput, xl & a)
{
for(int i=0;i<a.len;i++)
input >> a.v[i];
return input;
}
xl xl::operator+(xl & X, xl & Y)
{
int mun = X.len;
int *t=new int[mun];
for(int i=0;i<mun;i++)
t[i]=X[i]+Y[i];
return xl(t,mun)
}
xl xl::operator+(xl & X, xl & Y)
{
int mun = X.len;
int *t=new int[mun];
for(int i=0;i<mun;i++)
t[i]=X[i]-Y[i];
return xl(t,mun)
}
double xl::operator*(xl & X, xl & Y)
{
double y;
int mun = X.len;
int *t=new int[mun];
for(int i=0;i<mun;i++)
t[i]=X[i]*Y[i];
for(int j=0;j<mun;j++)
y=y+t[j];
return y;
}
void main()
{
int k;
cout<<"输入向量为几维?"<<endl;
cin>>k;
xl X(k), Y(k),Z(k);
cout<<"输入X"<<endl;
cin>>X;
cout<<"输入Y"<<endl;
cin>>Y;
cout<<"X+Y"<<endl;
Z=X+Y;
cout<<Z<<endl;
cout<<"X-Y"<<endl;
Z=X-Y;
cout<<Z<<endl;
cout<<"X*Y"<<endl;
cout<<X*Y<<endl;
}
***************************************************
错误:
error C2065: 'input' : undeclared identifier
warning C4552: '>>' : operator has no effect; expected operator with side-effect
error C2511: '+' : overloaded member function 'class xl (class xl &,class xl &)' not found in 'xl'
see declaration of 'xl'
'+' : overloaded member function 'class xl (class xl &,class xl &)' not found in 'xl'
see declaration of 'xl'
error C2511: '*' : overloaded member function 'double (class xl &,class xl &)' not found in 'xl'
see declaration of 'xl'


新人求教QAQ第一次发帖,如有问题,请见谅QAQ
[解决办法]
第一个错误是你敲错了:intput在底下却成了input没有定义
第二个就是:你的重载+操作符函数定义和实现不同,定义时只有一个参数,实现有两个函数。

读书人网 >C++

热点推荐