Listing 1: An extra method for memory access rights has been added to a class that is a potential victim of incorrect memory access
class Victim { public: // public interface // a setter method void setSomeData(/* ... */); // ... private: // internal data // ... protected: // a method for controlling // access to internal data enum MemoryAccessMode { noAccess, readOnly, readWrite }; // Sets memory access mode for the data members; // needs to be overrideable, if derived classes // add more data members. virtual void setMemoryAccessMode(MemoryAccessMode); }; End of Listing