#include <iostream>

using namespace std;

class Rat{
public:
    int getNum(){ return num; }
    int getDenom(){ return denom; }
    friend const Rat operator+(const Rat& lhs, const Rat& rhs);
    Rat(int n = 0, int d = 1): num(n), denom(d) {}

private:
    int num;
    int denom;
};


const Rat operator+(const Rat& lhs, const Rat& rhs){
    int n  = lhs.num * rhs.denom + rhs.num * lhs.denom;
    return Rat(n, lhs.denom * rhs.denom);
}


int main(){

    Rat a(1,2);
    Rat b(1,4);
    //    Rat c = a.operator+(b);

    //Rat c = a + b;
    //Rat *rp = &(a + b);
    //cout << c.getNum() << "/" << c.getDenom() << endl;

    Rat d = a + 2;
    cout << d.getNum() << "/" << d.getDenom() << endl;

    Rat e = 2 + a; //2.operator+(a)
    cout << e.getNum() << "/" << e.getDenom() << endl;
    return 0;
}

//Plus returns a Rat by value. If it returned a reference, the thing
//that the ref pointed to would go out of scope at the end of the
//statement; if a pointer, then sooner.

