169. Encapsulation

Question.4

A developer uses friend to allow a test class to access private members:

class CRC_Calculator {
private:
   uint32_t state;
   void update_state(uint8_t byte) { /* ... */ }
   friend class CRC_Test;  // Test class can access internals
public:
   uint32_t compute(const uint8_t* data, int len);
};

Is this a good use of friend?

Need Help? Refer to the Quick Guide below

Select Answer

Restart quiz!