Re: [Vala] inherited constructors



As in Java, except it's "base", not "super". :)

2009/7/10 pancake <pancake youterm com>:
I was trying to write some classes in Vala using basic inheritance but
looks like the compiler does not inherits the class constructors that
takes at least 1 argument. If the constructor gets no parameters it is
inherited.

Is this the correct way to do it or it is a bug in Vala? It will safe
me from lot of copypaste if I can just keep the same constructor for the
child classes.

It is possible to call upper class constructors or methods like in java?

public Child(string str) {
 super(str);
}

It is at least possible to do it :) And i think..a prefered way to work.

--------------------------

Here's an example:

$ cat base.vala
public class Base : Object
{
      public string str;

      public Base(string str) {
              stdout.printf("base constructor\n");
              this.str = str;
      }

      public virtual void foo() { /* empty */ }
}


$ cat child.vala
public class Child : Base
{
      public override void foo()
      {
              stdout.printf("Hello %s\n", this.str);
      }

}

void main()
{
      stdout.printf("Main\n");
      var ch = new Child("perro");
      ch.foo();
}

$ valac *.vala
child.vala:13.11-13.28: error: Too many arguments, method `Child.new' does
not take 1 arguments
      var ch = new Child("perro");
               ^^^^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
_______________________________________________
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]