Re: [Vala] multiple constructors



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.

Attachment: pgpujXqVW1mIq.pgp
Description: PGP signature



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