[Issue 5056] Warning against virtual method call from constructor

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Oct 16 10:15:09 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=5056


nfxjfg at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |nfxjfg at gmail.com


--- Comment #4 from nfxjfg at gmail.com 2010-10-16 10:14:32 PDT ---
The really bad thing is that D doesn't allow you to set up a sub class before
calling the super constructor. Consider this:

class Foo : Moo {
  int stuff;
  this(int stuff_) {
    this.stuff = stuff_;
    super();
  }
  override int get_stuff() {
     return stuff;
  }
}

This won't compile, because the compiler forces you to do the super ctor call
_before_ setting up any members. This was probably thought as a feature to
ensure "correct" construction, but it just doesn't work because the super ctor
could call virtual functions. And it's really hard to work this around.

This behaviour of super ctor calls and virtual functions has been badly
thought-through and doesn't increase productivity in the slightest. Sucks a
lot.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list