Thread overview
core dumped when run this simple D program.
Aug 26
Fox
Aug 26
Fox
August 26

import std.stdio;

class myClas_1 {
int a;
}

void main() {
myClas_1 c1;
writeln(c1.a);
}

===================
what's wrong? dmd and gdc both can compile these code, but can't run either.
DMD64 D Compiler v2.109.1
gcc 14.2.1 20240824 (GCC)
fedora 41
thanks!

August 26
Classes in D are heap objects, you have to allocate them.

``myClas_1 c1 = new myClas_1;``

The default is null.
August 26
On Monday, 26 August 2024 at 07:17:58 UTC, Richard (Rikki) Andrew Cattermole wrote:
> Classes in D are heap objects, you have to allocate them.
>
> ``myClas_1 c1 = new myClas_1;``
>
> The default is null.


thank you very much!