???C++??Щ?????NO
???????????? ???????[ 2013/1/4 10:27:35 ] ????????
????1???ò????????÷????
????????????????????????????÷???????????????????????????????Ч????????????????????????????????
?????????′???
class Rational{
public:
Raional( int numerator = 0?? int denominator =1);
...
private:
int d?? d;
friend Rational operator* (const Rational& lhs?? const Raional& rhs) ;
};
Rational Rational::operator* (const Rational& lhs??const Raionl&rhs)
{
return Rational result(lhs.n*rhs.n??lhs.d*rhs.d);
}
}
?????????????????????????????????????????????????????????????????????????????????????????????????Ч????
??????????????????????????????????????statck???д??????????????heep???д?????
People p(a??b) //??д???
People *p = new People(a??b) //???д???
???????????????????д?????????????????????????????????????????????????????
const Rational& operator* (const Rational& lhs?? const Rational & rhs)
{
Rational result(lhs.n*rhs.n??lhs.d*rhs.d);
return result;
}
?????????????stack?????????????????????κκ???????????????????????????????????????????????????????????????????????ζ??reference?????????????
???????????????д???
const Rational& operator* (const Rational& lhs?? const Rational & rhs)
{
Rational* result=new Rational(lhs.n*rhs.n??lhs.d*rhs.d);
return *result;
}
??????????????????????new??????????????delete?????????????????????????????
Rational w??x??y??z;
w=x*y*z;
?????????????????????????operator*????ζ??new?????Σ?????delete???Ρ???????????к???????opertaor*??????????Щdelete?????????????????????????????????????й???
???????????????????????????????????????static Rational????
const Rational & operator*(const Rational& lhs??const Rational & rhs)
{
static Rational result;
result = ...;
return result;
}
??????????????????????????????£?????д??????????????????????????′??????????
bool operator == (const Rational& lhs?? const Rational& rhs);
...
Raional a??b??c??d;
if((a*b) == (c*d)
{
...
}
????????if??????????a??b??c??d????????true???????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11