[Vala] Base class constructor



Hi,

I've been playing with vala quite a bit and found a problem. I ported
simple gtk application to vala just to see how it will work.

I can't figure out how to call base class constructor. I've looked at
grammar spec and it hase base keyword. This is necessary so that if I
derive class from some exiting Gtk class (say Gtk.Window)
it gets properly initialized.

I'm using following code:

using Gtk;
using GLib;

namespace Pkgsetup
{
  public class MainWindow : Window
  {
    private Button b;

    public construct()
    {
      //XXX: here I need call to constructor of Window
      b = new Button();
      b.label = "Close";
      add(b);
      show_all();
    }
  }

  static int main (string[] args)
  {
    var main_win = new MainWindow();
//    Gtk.init(args);
    Gtk.main();
    return 0;
  }
}

Or simpler non-gtk code.

using GLib;

class Test.Base
{
    public construct()
    {
      stdout.printf("base\n");
    }
}

class Test.Ext : Test.Base
{
    public construct()
    {
      stdout.printf("ext\n");
    }
}

namespace Test {
static int main (string[] args)
{
    var ex = new Ext();
    return 0;
}
}

How can I call base class constructor?

Thanks,
Ondrej Jirman



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