运算符号重载问题
class S
{
public:
S(const int in1):a(in1){}
S operator+ (S& other);
friend const S operator* (S& one , S& theother); //ok
// S operator* (S& one, S& theother); //fail
void display();
private:
int a;
};
S S::operator+(S& other)
{
return (a+other.a);
}
const S operator* (S& one, S& theother) //ok
{
return (one.a * theother.a);
}
//S S::operator* (S& one, S& theother)//fail
//{
// return (one.a * theother.a);
//}
void S::display()
{
cout<<"result is "<< a << endl;
}
void main()
{
S n(5),m(6),o(0);
o = n + m;
o.display();
o = n * m;
o.display();
}