标签:
类成员函数:
bool operator ==(const point &a)const
{
return x==a.x;
}
友元函数:
friend bool operator ==(const point &a,const point &b)
{
return a.x==b.x;
}
两种重载方式的比较:
(1)单目运算符、=、()、[]、->使用类成员函数,其它双目运算符使用友元函数
(2)类型转换函数只能定义为类成员函数
(3)运算会修改类成员是使用类成员函数
(4)有隐式类型转换使必须使用友元函数
(5)运算符需具有可交换性时用友元函数
(6)两个参数都需要限定const时用友元函数
标签:
原文地址:http://www.cnblogs.com/sea5/p/4624814.html