64,646
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class point
{
private:
int val;
bool hb;
bool buf;
public:
point ():hb(0),buf(0),val(1){}
point (const point &temp){val=temp.val;hb=temp.hb;buf=temp.buf;}
point operator +(const point& temp)
{
point reval;
if (hb == temp.hb&& buf==temp.buf )
reval.val=val+temp.val;
return reval;
}
friend int &operator =(int &tmp1, point &tmp2 )
{
tmp1=tmp2.val;
return tmp1;
}
};
int main()
{
point table;
int sanheng ;
sanheng=table;
cout <<sanheng<<endl;
system("pause");
}
point (int temp){val=temp;}
赋值运算符严格地说是一个双目运算符。 它必须是非静态成员函数。没有operator=可以说明为非成员函数。它不能被派生类继承。 如果不存在缺省的operator=函数,则编译器会为该类生成一个缺省的函数。