let's say if this is my code
class Rational
{
public:
Rational (Rational ©Object);
Rational add (Rational rhs);
private:
int mNum;
int mDen;
};
Rational :: Rational (Rational ©Object)
{
this->mNum = copyObject.mNum;
this->mDen = copyObject.mDen;
}
Rational Rational:: add (Rattional rhs)
{
this->mNumerator = (this->mNumerator * rhs.mDenominator) +
(rhs.mNumerator * this->mDenominator);
this->mDenominator = this->mDenominator * rhs.mDenominator;
return *this;
}
int main (void)
{
Rational r1(10,3), r2 (20,3) //let just assume I have a constructor for initialize
r1.add(r2);
}
I'm not quite sure what does Rational :: Rational (Rational ©Object)
do
Does it mean that if I don't have that function, I will make a copy of r2, and if I have that function I will connect the local variable in Rational Rational:: add (Rattional rhs)
to r2 in main()
?
1 more thing, how does the compiler know when to call that function?
I'm new to c++, please explain as easiest as you can.
Thank you!