new class howto?

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Jul 31 05:02:51 PDT 2007


newbie wrote:
> module C
> 
>  XXX tester = new XXX();
> 
> 
> it will always generate an error during compilation:
> 
>       non-constant expression
> 
> when i try to do that in a function, then i will get an exception.

You can only use constant expressions as initializers for global 
variables, so dynamic memory allocation is disallowed. To do what you 
want, use:
---
module C;

XXX tester;

static this() {
     tester = new XXX();
}
---


More information about the Digitalmars-d-learn mailing list