October 25, 2003 bug: ctors with inheritance | ||||
---|---|---|---|---|
| ||||
The following doesn't compile: class A : Exception {} void main() { throw new A; } DMD outputs: "constructor this (char[]msg) does not match argument types ()" If I write throw new A("something"); instead, it outputs exactly the same. Two more things: someone (sorry, can't remember) once said that error messages regarding constructor didn't specify which line. That's annoying. Also, I can't remember which was the syntax for not writing "this(char[]msg){super(msg);}" for each class derived from Exception. Can somebody please refresh my mind? ------------------------- Carlos Santander --- Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.530 / Virus Database: 325 - Release Date: 2003-10-22 |
October 25, 2003 Re: ctors with inheritance | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Santander B. | > The following doesn't compile: > > class A : Exception {} > void main() { > throw new A; > } > > DMD outputs: "constructor this (char[]msg) does not match argument types ()" > If I write throw new A("something"); instead, it outputs exactly the same. You have to satisfy one of the super class' constructors; the compiler only knows how to insert a call to super() if it takes no parameters, you must explicitly call one otherwise. > Two more things: someone (sorry, can't remember) once said that error messages regarding constructor didn't specify which line. That's annoying. > > Also, I can't remember which was the syntax for not writing > "this(char[]msg){super(msg);}" for each class derived from Exception. Can > somebody please refresh my mind? Constructors aren't inherited like other member functions (which I think they should...) so you have to write that. |
Copyright © 1999-2021 by the D Language Foundation