Re: [Vala] multiple constructors



Thanks for the quick response Andrea! so this limitation is also for
method names I think....

Anyway it should be possible to generate automatic names from function
parameters
example:
public Button()
public Button(string stock_id) ===> public Button.string(string stock_id)

also another question (though not subject related). is it possible to
call assert() in the constructor, or the memory allocated is lost?
if we are in this case, how to deal with preconditions of constructor
parameters?
thanks


2008/9/23 Andrea Bolognani <eof kiyuko org>:
On Tue, 23 Sep 2008 00:12:35 +0200
"Nicolò Chieffo" <84yelo3 gmail com> wrote:

Is it possible to declare multiple constructors for the same class (of
course with different parameter types/number)?
It seems I'm not able to do it, since valac complains.
why? is this a glib limitation?

Declaring multiple constructor is possible; the Gtk.Button class, for
example, has four different constructors:

   public Button ();
   public Button.from_stock (string stock_id);
   public Button.with_label (string label);
   public Button.with_mnemonic (string label);

This unusual naming scheme is needed since C (the target language of Vala)
cannot cope with polymorphic functions. This convention is used thorough
GLib and GLib-based libraries to work around this limitation.

--
Andrea Bolognani <eof kiyuko org>
Resistance is futile, you will be garbage collected.

_______________________________________________
Vala-list mailing list
Vala-list gnome org
http://mail.gnome.org/mailman/listinfo/vala-list





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]