读书人

哪位给小弟我讲讲运算附重载并给个简

发布时间: 2012-02-07 17:45:36 作者: rapoo

哪位给我讲讲运算附重载,并给个简单的例子,20分全给你了。。。。
RT

[解决办法]
private:
int x;
float y;
string str;
public:
test(int a, float b, string s):x(a), y(b), str(s){}

bool operator ==(const test& a) const
{
if ( (a.x == x) && (a.y == y) && (a.str == str) )
{
return true;
}
else
return false;
}
bool operator != (const test& a) const
{
if ((a.x != x) || ( a.y != y ) || (a.str != str))
{
return true;
}
else
{
return false;
}
}
friend ostream& operator < <(ostream& s, const test& a)
{
s < < "test: " < < a.x < < " " < < a.y < < " " < < a.str < < endl;
return s;
}

};

读书人网 >C++

热点推荐