[Gambas-user] Class startup?

Tobias Boege taboege at ...626...
Thu May 18 17:23:44 CEST 2017


On Thu, 18 May 2017, PICCORO McKAY Lenz wrote:
> 2017-05-18 9:13 GMT-04:00 Tobias Boege <taboege at ...626...>:
> 
> > You can also specify parameters to the _new() method like
> >
> >   ' In MyClass.class:
> >   Public Sub _new(X As Integer)
> >     ' ...
> >   End
> >
> 
> a question: can be "Optional" allowed in constructor arguments..?
> 
> its possible, so its the same as override in C:
> 
> Public Sub _new(Optional x As String = "pepe")
> 
>   Print " es " & x
> 
> End
> 
> gambas its wonderfull....
> 

Yes, they can be optional.

If you use optional constructor arguments you have to be careful with
inheritance, though! Along the inheritance lineage, all constructor
arguments are divided into two camps: mandatory and optional arguments.
When the final inherited constructor signature is computed, both camps
are sorted separately with the elders' arguments first and then all the
mandatory arguments precede the optional arguments, e.g.

  ' Parent.class
  Public Sub _new(ParentArg, ParentArg2, Optional ParentOpt)

  ' Child.class
  Inherits Parent
  Public Sub _new(ChildArg, Optional ChildOpt)

results in the following complete signature for Child._new():

  _new(ParentArg, ParentArg2, ChildArg, ParentOpt, ChildOpt)

Note that the optional argument of the parent comes *after* the mandatory
argument of the child. There is an extra section in the object model wiki
page about this [1].

Regards,
Tobi

[1] http://gambaswiki.org/wiki/doc/object-model#t18

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk




More information about the User mailing list