C/C++ Programming Style Guidelines



/* Straight C */
struct complex {
int r;
/* real */
int i;
/* imaginary */
};
typedef struct complex Complex;
// C++ interface example
class Canvas {
public:
enum Pen_style {
NONE = 0,
PENCIL,
BRUSH,
BUCKET
};
Canvas();
~Canvas();
void set_pen_style(Pen_style p);
...
private:
int cached_x_;
// to avoid recomputing coordinates
int cached_y_;
};
// C++ usage example
Canvas sketch_pad;
sketch_pad.set_pen_style(Canvas::BRUSH);