IonicWind Software

Aurora Compiler => General Discussion => Topic started by: Zen on January 11, 2006, 05:59:57 AM

Title: Class Constructor Errors
Post by: Zen on January 11, 2006, 05:59:57 AM
Hi Paul.

I have made a few classes and for some reason if i declare my class variable outside of the main subroutine my class constructor is not being called. So whenever i am calling a method i need to call the class constructor manually first. This is happening in my Raw internet class. The constructor initializes the winsock library so that you dont have to do it manualy. For some reason it doesnt work outside of main or another subroutine.

Any ideas?

Lewis
Title: Re: Class Constructor Errors
Post by: Ionic Wind Support Team on January 11, 2006, 07:27:24 AM
Global classes are not supported yet.
Title: Re: Class Constructor Errors
Post by: Zen on January 11, 2006, 08:57:37 AM
Sorry Paul can you explain in a little more detail please as i dont quite understand.

Lewis
Title: Re: Class Constructor Errors
Post by: Ionic Wind Support Team on January 11, 2006, 12:00:07 PM
Class constructors/destructors are called only if the class in instanced as a local subroutine variable or with NEW.  If you define a class instance in global program scope then the compiler has nowhere to put the code to call the constrructor, or set up the vtable.

Myclass cl;  //global scope doesn't work

global sub main()
{
MyClass cl2; //local scope works fine.
}
Title: Re: Class Constructor Errors
Post by: Zen on January 11, 2006, 12:45:44 PM
Any idea when this will be fixed?

Lewis
Title: Re: Class Constructor Errors
Post by: Ionic Wind Support Team on January 11, 2006, 01:26:37 PM
Nope.  Probably not until the beta.

The compiler will have to inject code into your main subroutine to construct any global classes.  The problem is if your using a project, and you compile a different file with global classes there is no where for the compiler to inject code.  It will require a lot of thinking on my part ot get it to work right.

Create you classes dynamically, or just use a global pointer which is more common with us C tyoes;

global g_cl
MyClass *g_cl;  //OK since it's a pointer

global sub main()
{
MyClass cl;
g_cl = &cl;  //valid for life of the application now;l


}

Then in some other file you can use the extern keyword.

extern g_cl as pointer;

You'll need to typecase it here since extern doesn't undersand the "*" syntax yet.

Paul.
Title: Re: Class Constructor Errors
Post by: Parker on January 11, 2006, 02:51:10 PM
Is it possible to do
extern int x;
or only by using the 'AS' keyword?
Title: Re: Class Constructor Errors
Post by: Ionic Wind Support Team on January 11, 2006, 04:29:40 PM
Not yet.  Haven't changed the extern syntax since the beginning.