#include <iostream>

using namespace std;

class Number {
    double x;
public:
    void    set(double);
    Number &add(double);
    Number &subtract(double);
    Number &multiply(double);
    Number *divide(double);
    void    info(const char*);
};

void Number::set(double x) { // set the value of property Number::x
    this->x = x;             // name/identifier hiding
}

Number &Number::add(double x) {
    this->x += x;
    printf("this: %p\n", this);
    return *this;  // dereference wyłuskanie
}

Number &Number::subtract(double x) {
    this->x -= x;
    printf("this: %p\n", this);
    return *this;
}

Number &Number::multiply(double x) {
    this->x *= x;
    return *this;
}

Number *Number::divide(double x) {
    this->x /= x;
    return this;
}

void Number::info(const char *s) {
    cout << s << " " << x << endl;
}

int main() {
    Number L;

    printf("&L: %p\n", &L);

    L.set(10);
    L.info("set                   :");
    
//    L.add(5);
//    L.subtract(7);
//    L.info("add 5 . subtract 7    :");

//    return 0;

    // cascaded function call
    
    L.add(5).subtract(7).info("add 5 . subtract 7    :"); 
    L.multiply(2).divide(4)->add(1).info("multiply 2 . divide 4 :");

    // x + y - z
    // -(+(x, y), z) 
    // x.+(z).-(z)
}
