Constructors: Another Example
counter apples; // Constructor called!
counter oranges; // Constructor called!
// Note, we haven’t explicitly initialized
// the counter to 0 -- the constructor
apples.increment_counter();
apples.increment_counter();
printf(“%d apples and %d oranges!\n”,
apples.query_counter(), // 2
oranges.query_counter()); // 0
public: // ignore this for now
// Normal member functions
void increment_counter() { i++; }
void decrement_counter() { i--; }
int query_counter() { return i; }
void set_counter(int new_value) {
// The constructor -- it has the same
// name as the class itself