Re: [Vala] instantiation via base class constructor



Andre Kuehne <andre kuehne gmx net> writes:

Hello,

i am new to Vala, played with it the last two days and have now a bunch of open questions.
Here's one of them: Is it possible to instantiate a class via a
constructor of one of its base classes? For example the following does
not work:

class Aaa {
      public int x;
      Aaa(int x) { this.x = x; }
      public virtual void test() { stdout.printf("%d\n", this.x); }
}

class Bbb : Aaa {
      public override void test() { stdout.printf("%d\n", -this.x); }
}


The default constructor is used. Please note that the x will be not assigned.

void main() {
      new Bbb(5).test();

new Bbb(5).test();

}

$ valac super.vala
super.vala:13.2-13.11: error: Too many arguments, method `Bbb.new' does not take 1 arguments
        new Bbb(5).test();
        ^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)

Thanks in advance!
Andre


Regards
-- 
I've probably left my head... somewhere. Please wait untill I find it.
Homepage (pl_PL): http://uzytkownik.jogger.pl/
(GNU/)Linux User: #425935 (see http://counter.li.org/)




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