Ecere SDK/eC Forums • View topic - [Solved]Anonymous class instance?




Ecere SDK/eC Forums

Ecere Developers Community

[Solved]Anonymous class instance?

General help with the eC language.

[Solved]Anonymous class instance?

Postby samsam598 » Wed Aug 24, 2011 2:27 am

After a second thought,I don't think it so obvious to convince myself.Given below code
Code: Select all

MessageBox {type=ok,text="caption",contents="message"}.Modal();


I can't see MessageBox {} in the Dao so far.Per my understand, MessageBox {...} is an anonymous class instance of class MessageBox,the invoke the method Modal().Please correct me if I was totally wrong.Thanks.

Regards,
Sam
Last edited by samsam598 on Thu Sep 08, 2011 12:30 am, edited 1 time in total.
samsam598
 
Posts: 208
Joined: Thu Apr 14, 2011 9:44 pm

Re: Anonymous class instance?

Postby jerome » Wed Aug 24, 2011 3:37 am

That's correct.

It could be written as a named instantiation this way:

MessageBox msgBox {type=ok,text="caption",contents="message"};
msgBox.Modal();

Then the first line would be a declaration (needs to be at the top of the block), and the second line a statement. The all in one line with anonymous declaration is a statement.

You could also do:

MessageBox msgBox; msgBox = {type=ok,text="caption",contents="message"}; (an inferred type anonymous instantiation as an expression to an assignment)
or
MessageBox msgBox; msgBox = MessageBox {type=ok,text="caption",contents="message"}; (an explicit anonymous instantiation as an expression to an assignment)
or
MessageBox msgBox = {type=ok,text="caption",contents="message"}; (an inferred type anonymous instantiation as an expression to a declaration initializer)
or
MessageBox msgBox = MessageBox {type=ok,text="caption",contents="message"}; (an explicit type anonymous instantiation as an expression to a declaration initializer)

With the exception of the declaration/statement difference (and the syntax errors you may get because eC is strict on declarations before statements), they are pretty much all equivalent.

The only other difference is that the named instantiation (the first one I wrote at the top) would auto increment/decrement the reference count when it applies (at the moment, only as a member instantiation or a global object, later on when eC supports it during the scope of the block).

I'm not sure yet how anonymous instantiation will behave in regards to reference counting in the future :) At the moment nothing is done, they have a 0 _refCount.

Regards,

Jerome
jerome
Site Admin
 
Posts: 622
Joined: Sat Jan 16, 2010 11:16 pm


Return to eC Language

Who is online

Users browsing this forum: No registered users and 4 guests

cron