为什么重载不对(速求解答)
错误:no match for ‘operator<<' in 'std::cout<<c3.MySet::display()//容纳集合类MySet,容纳int类型的元素,允许增删
//重载运算符+,表示两个集合的并集,重载运算符-,表示两个集合的交集
//<<,以“{1,25,18,27}”输出
#include<iostream>
//#incldue<operator>
using namespace std;
class MySet
{
private:
int *a;
int size;
int k;
public:
MySet()
{
a=new int[size];
size=0;
};
void getdata();
void getArray();
void add();
void erase();
void display();
//friend MySet operator+(MySet &setArray1,MySet &setArray2);
friend MySet operator-(MySet &setArray1,MySet &setArray2);
//friend ostream&operator<<(ostream&,MySet&);
};
void MySet::getdata()
{
cout<<"请输入集合个数:"<<endl;
cin>>size;
}
void MySet::getArray()
{
getdata();
cout<<"请输入"<<size<<"个整数元素:"<<endl;
for(int i=0;i<size;i++)
cin>>a[i];
cout<<endl;
display();
}
void MySet::display()
{
cout<<"{";
int i;
for(i=0;i<size-1;i++)
{
cout<<a[i]<<",";
}
cout<<a[i]<<"}";
cout<<endl;
}
void MySet::add()
{
cout<<"请输入需要增加的元素:"<<endl;
cin>>a[size++];
cout<<"{";
int i;
for(i=0;i<size-1;i++)
{
cout<<a[i]<<",";
}
cout<<a[i]<<"}";
}
void MySet::erase()
{
cout<<"请输入需要删除的元素:"<<endl;
int i,j;
cin>>a[j];
cout<<"{";
for(i=0;i<size-1;i++)
{
if(a[i]==a[j])continue;
else
{
cout<<a[i]<<",";
}
}
cout<<a[i]<<"}";
cout<<endl;
}
/*MySet operator+(MySet &setArray1,MySet &setArray2)
{
int k=0;
int size=0;
int*c=new int[size];
for(int i=0;i<size;i++)
{
for(int j=0;j<size;j++)
{
if(setArray1.a[i]==setArray2.a[i])
{
c[k++]=setArray1.a[i];
}
else
{
c[k++]=setArray2.a[i];
}
}
}
}*/
MySet operator-(MySet &setArray1,MySet &setArray2)
{
MySet mix;
int k=0;
for(int i=0;i<setArray1.size;i++)
{
for(int j=0;j<setArray2.size;j++)
{
if(setArray1.a[i]==setArray2.a[j])
{
mix.a[k++]=setArray1.a[i];
}
}
}
return mix;
}
/*ostream&operator<<(ostream&output,MySet&c)
{
output<<"{"<<c<<"}";
return output;
}*/
int main()
{
MySet setArray1;
cout<<"集合1为:"<<endl;
setArray1.getArray();
setArray1.add();
MySet setArray2;
cout<<"集合2为:"<<endl;
setArray2.getArray();
setArray2.erase();
//MySet sum;
//sum=setArray1+setArray2;
//cout<<"集合1和集合2的并集为:";
//cout<<sum.display();
cout<<"集合1和集合2的交集为:";
MySet c3;
c3=setArray1-setArray2;
cout<<c3.display()<<endl;
return 0;
}