On 01/06/2014 09:32 PM, Antonio Corbi wrote:
If I derive a class from Gtk.Window like this:
class Derived : Window {
this (string n) { super (n); b = 10; }
private:
invariant () { assert ( b > 0 ); }
int b;
}When creating a Derived object, the Derived.invariant is called inside the "super (n)" call ... and as 'Derived.b' isn't initialized yet...it gives an error!
If I change the base class from Gtk.Window to another class (a class written by me) like:
class Base {
this (string n) { name = n; }
private string name;
}The DbC works as expected.
Am I missing something here?Thanks for your hellp
The constructor of Window calls setTitle which is a public function so
the invariant is called before and after it.
I this case you could use super(WindowType.TOPLEVEL); and then call
setTitle afet you're done initializing. although the D documentation
states you should not call public functions from the constructor, for
the above reason.