Initializing function parameters

 

I am writing some utility functions that I can add to any experts/indicators I create via an include file. For example:


//--------------------------------------------------------------------------------
//Function: CreateVlineObject
//Purpose:  Creates VLine objects. VLines take one time coordinate.
//Inputs:   int Window_ - Window number detrmined in calling code
//          string LabelPrefix
//          string sObjectName
//          datetime time1 - time position of the line
//          color linecolour
//          int linewidth
//          int linestyle
//          bool ray - if true line extends as a ray 
//          bool background - OBJPROP_BACK sets the object as background or foreground... 
//                            it fills rectangles and triangles and ellipses or leaves 
//                            only an outline.
//--------------------------------------------------------------------------------
void CreateVlineObject(int Window_,string LabelPrefix="",string sObjectName="",datetime time1,
                       color linecolor,int linewidth,int linestyle, bool ray=false,bool background=false)

//--------------------------------------------------------------------------------
//Function: CreateTrendObject
//Purpose:  Function takes various object parameters and creates trend line object
//Inputs:   
//Returns:  (void)
//--------------------------------------------------------------------------------
void CreateTrendObject(string IndicatorName_,string NamePrefix,string sObjectName,
                       datetime time1,double price1, datetime time2,double price2, 
                       color linecolour,int linewidth,int linestyle, bool ray=false, 
                       bool background=false)


Why is it the compiler demands that I initialize all the parameters in the first function (I haven't yet), but doesn't mind in the second?

 

It's because when u give default values for passed parameters there cannot be gaps from the right. So for example u need to have:

void CreateVlineObject(int Window_,datetime time1, color linecolor,int linewidth,int linestyle, string LabelPrefix="",
                       string sObjectName="", bool ray=false,bool background=false)

Instead of:

void CreateVlineObject(int Window_,string LabelPrefix="",string sObjectName="",datetime time1,
                       color linecolor,int linewidth,int linestyle, bool ray=false,bool background=false)
So that all params with default values are rightmost... Hope my explanation is clear.
Reason: