91. Basics of Classes

Question.8

A developer needs to define a GPS coordinate and a UART driver. Which should be a struct and which a class?

// Option A: Both as classes
class Coordinate { public: float lat, lon; };
class UART_Driver { /* private state + public API */ };

// Option B: Coordinate as struct, Driver as class
struct Coordinate { float lat, lon; };
class UART_Driver { /* private state + public API */ };

Which follows embedded C++ best practice?

Need Help? Refer to the Quick Guide below

Select Answer