#include class counter { int count; public: counter(int start) : count(start) {} int operator() () { count += 1; return count; } auto get_remote_increment(){ int *cref = &count; // Don't use this idea without thinking about it for a really long time return [cref](){ (*cref)++; }; } }; int main(){ counter from_2(2); printf("%d\n", from_2()); printf("%d\n", from_2()); counter from_17(17); printf("%d\n", from_17()); printf("from_2 again: %d\n", from_2()); counter copy_of_from_2 = from_2; printf("copy: %d\n", copy_of_from_2()); printf("copy: %d\n", copy_of_from_2()); printf("copy: %d\n", copy_of_from_2()); printf("from_2 again: %d\n", from_2()); auto remote_incrementer = from_2.get_remote_increment(); remote_incrementer(); remote_incrementer(); printf("from_2 again: %d\n", from_2()); remote_incrementer(); remote_incrementer(); printf("from_2 again: %d\n", from_2()); }