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
[creator]
[destructor]
function
virtual function
virtual function=0
static function
friend function
friend class

Class Syntax#

  • The class name should be written using uppercase letters

  • static members (data and functions) should be defined using names in which the first letter is uppercase.

  • non static members should be defined in lowercase.

  • comments will be inserted before the class definition.

  • constructors and destructors will be defined before the other member functions.

  • short comments can be inserted in 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 exemple 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();
};