C++'s this() equivalent?

Steven Schveighoffer schveiguy at gmail.com
Fri Jun 16 00:35:48 UTC 2023


On 6/15/23 8:31 PM, zjh wrote:

> Because disabled `this()`, the behavior of `this(int i)`is inconsistent 
> and cannot achieve similar `RAII` as `C++`. What should I do?
> 

You cannot have parameter-less constructors in D structs. However, 
destruction works the same.

Instead, you can use factory functions to initialize.

But there is no way in D to have e.g.:

```d
B b; // runs a constructor
```

-Steve


More information about the Digitalmars-d-learn mailing list