digitalmars.D.learn - core dumped when run this simple D program.
- Fox (15/15) Aug 25 import std.stdio;
- Richard (Rikki) Andrew Cattermole (3/3) Aug 26 Classes in D are heap objects, you have to allocate them.
- Fox (3/6) Aug 26 thank you very much!
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!
Aug 25
Classes in D are heap objects, you have to allocate them. ``myClas_1 c1 = new myClas_1;`` The default is null.
Aug 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!
Aug 26