30 lines
531 B
C++
30 lines
531 B
C++
#include <iostream>
|
|
#include <ostream>
|
|
class A {
|
|
long long counter = 0;
|
|
|
|
public:
|
|
A() : counter{0} {}
|
|
A operator()() {
|
|
A ret = *this;
|
|
ret.counter++;
|
|
return ret;
|
|
}
|
|
A operator[](int dummy) {
|
|
A ret = *this;
|
|
ret.counter--;
|
|
return ret;
|
|
}
|
|
friend std::ostream &operator<<(std::ostream &lhs, A const &rhs) {
|
|
lhs << rhs.counter;
|
|
return lhs;
|
|
}
|
|
};
|
|
|
|
int main(void) {
|
|
A a;
|
|
std::cout << a[0] << std::endl;
|
|
std::cout << a[0]() << std::endl;
|
|
std::cout << a[0]()() << std::endl;
|
|
return 0;
|
|
}
|