Values & References15 / 16
Up next

A reference member

#include <print>

struct Logger {
    // a reference member must be set in the initializer list
    int& counter;
    explicit Logger(int& c) : counter(c) {}
    void tick() {
        ++counter;
    }
};

int main() {
    int hits = 0;
    Logger log{hits};
    log.tick();
    log.tick();
    std::println("{}", hits);
}
What you're solving

bind an alias inside a struct