What is the output of the following C++ program?
#include <iostream>
class Counter {
int n_ = 0;
public:
void tick();
int value() const;
};
void Counter::tick() { n_ += 2; }
int Counter::value() const { return n_; }
int main() {
Counter a, b;
a.tick(); a.tick(); b.tick();
std::cout << a.value() << ' ' << b.value() << '\n';
return 0;
}
Defining the functions outside with Counter:: makes no difference to behaviour. Each object has its own n_.