1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;
 
class Accumulator {
    int value;
public:
    Accumulator(int value) { this->value = value; } // 매개 변수 value로 멤버 value를 초기화한다.
    Accumulator& add(int n) { value += n; return (*this); } // value에 n을 더해 값을 누적한다.
    int get() { return value; } // 누적된 값 value를 리턴한다.
};
 
int main() {
    Accumulator acc(10);
    acc.add(5).add(6).add(7);
    cout << acc.get() << endl;
}
cs


+ Recent posts