Class-Inheritancing Error

H. S. Teoh hsteoh at qfbox.info
Mon Jul 28 18:02:45 UTC 2025


On Sun, Jul 27, 2025 at 05:02:35PM +0000, user1234 via Digitalmars-d-learn wrote:
[...]
> Simply because because if OP writes
> 
> ```
> class Person{
>     string name;
>     this(string name){this.name=name;}
> }
> class Someone:Person{
> }
> void main(){
>     Someone x=new Someone("Bob");
> }
> ```
> 
> then he gets rewarded with
> 
> > Error: class `Someone` cannot implicitly generate a default constructor
> > when base class `Person` is missing a default constructor

Oh I see.  So just write a forwarding ctor:

```
class Someone : Person {
	this(string name) { super(name); }
	...
}
```

Or use the mixin template I wrote in the other thread to auto-generate
forwarding ctors, if you have many subclasses that need forwarding.


T

-- 
If you can't deal with your problems, try becoming a school bus driver.  Then all your problems will be behind you.


More information about the Digitalmars-d-learn mailing list