www.digitalmars.com         C & C++   DMDScript  

D - bug: ctors with inheritance

reply "Carlos Santander B." <carlos8294 msn.com> writes:
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
Oct 24 2003
parent "Vathix" <vathix dprogramming.com> writes:
 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.
Oct 25 2003