79367213

Date: 2025-01-18 13:27:35
Score: 1
Natty:
Report link

Here's what I ended up doing. @wohlstad said "you can encapsulate a single boolean parameter (with current and previous values) in a class" and that gave me the idea to do this:

class MemorableVar {
    public: 
        MemorableVar() {
            x = false;
            prev_x = false;
        };

        // Setters:
        void set(bool x0) {prev_x = x; x = x0;};

        // Getters:
        bool get() {return x;};
        bool get_prev() {return prev_x;};
        bool changed() {return (x != prev_x);};

    private:
        bool x;
        bool prev_x;
};

In this approach, you use setters to control the variable value, and the previous value is remembered every time you do so.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @wohlstad
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: James Strieter