new class howto?

newbie newbie at nospam.com
Tue Jul 31 05:49:17 PDT 2007


Frits van Bommel Wrote:

> 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();
> }
> ---

thank you for the reply.

it will compile, but it will fail with an exception.
that will also happen if i declare the variable in a function and than try to do my new.

void testers() {
	  XXX tester = new XXX(); <---- exception
	  tester.Stop(); 
}

could it be, that the extern(Windows) is a problem?




More information about the Digitalmars-d-learn mailing list