Style, definition#
Class Organisation#
The following order will be used when defining a class.
class T {
private :
protected :
public :
};
The class name should be written using uppercase letters. private
members are defined before protected members which are defined
before public members. In each group, members are defined in the
following order.
enum
data
static data
[constructor]
[destructor]
function
virtual function
virtual function=0
static function
friend function
friend class
Class Syntax#
Class names should be written in uppercase letters.
Static members (data and functions) should have names starting with an uppercase letter.
Non-static members should use lowercase names.
Comments should be placed before the class definition.
Constructors and destructors should be defined before other member functions.
Short comments can be inserted inside the class definition.
Example#
// ************* Comment
//
// DRAW_OBJECT :
// base class for all object that can be drawn
// draw() is defined as virtual pure, so don't forget
// to define it when you add your own object
//
// Add a new item to OBJECT_TYPE enumeration when you
// create a new object inheriting from DRAW_OBJECT
// SQUARE :
// this is an example for a fully define DRAW_OBJECT
// note that draw() has been defined and reset()
// overloaded.
class DRAW_OBJECT : public OBJECT {
private :
int left,right,top,bottom; // position of the corners
static int Nb_draw_object;
protected :
enum OBJECT_TYPE { SQUARE, TRIANGLE; };
virtual void reset();
public :
DRAW_OBJECT();
DRAW_OBJECT(const DRAW_OBJECT&);
virtual void draw()=0;
static int Nb_object() { return Nb_draw_object; }
friend class PLOTTER;
};
class SQUARE : public DRAW_OBJECT {
private :
int size; // length of one side
void reset();
public :
SQUARE();
SQUARE(const SQUARE&);
virtual void draw();
};