[ create a new paste ] login | about

Link: http://codepad.org/fBYVCpFN    [ raw code | output | fork ]

rplantiko - C++, pasted on Jun 18:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// Example for method chaining in C++

class F {
  private: 
    unsigned int eax;
  public: 
    F() : eax(0) {} 
    F& lda(unsigned int value) { eax = value; return *this;  }
    F& adc(unsigned int value) { eax += value; return *this; }
    F& inc() { eax++; return *this;}
    F& dec() { eax--; return *this;}
    unsigned int get() { return eax; }
  };

int main() {
  F cpu;
  cout << cpu.lda(10).inc().inc().adc(5).get();
  }


Output:
1
17


Create a new paste based on this one


Comments: