[Solved]Anonymous class instance?

General help with the eC language.
Post Reply
samsam598
Posts: 212
Joined: Thu Apr 14, 2011 9:44 pm

[Solved]Anonymous class instance?

Post by samsam598 »

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.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Anonymous class instance?

Post by jerome »

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
Post Reply