new class howto?

newbie newbie at nospam.com
Tue Jul 31 06:31:55 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();
> }
> ---
it is seeminglx not possible to call d functions or initialize d classes from a function that is decorated with
extern(Windows)

extern (Windows) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	testery();
    DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_MAIN), null, &Dialog_Main);
    return 0;
}


void testery() {
	  XXX testerx = new XXX;
	  testerx.Stop();
}


how does one call a D function or do a XXX testerx = new XXX; in such a function?




More information about the Digitalmars-d-learn mailing list