169. Encapsulation

Question.2

A Buffer class returns a raw pointer to its private data:

class Buffer {
   uint8_t data[64];
   int head = 0;
public:
   uint8_t* getData() { return data; }
};

Buffer buf;
uint8_t* raw = buf.getData();
raw[100] = 0xFF;  // Write past end!

What is the encapsulation problem?

Need Help? Refer to the Quick Guide below

Select Answer

Restart quiz!