Ecere SDK/eC Forums
http://ecere.org/community/
Print view

[Solved]Anonymous class instance?
http://ecere.org/community/viewtopic.php?f=1&t=163
Page 1 of 1
Author:  samsam598 [ Wed Aug 24, 2011 2:27 am ]
Post subject:  [Solved]Anonymous class instance?

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
Author:  jerome [ Wed Aug 24, 2011 3:37 am ]
Post subject:  Re: Anonymous class instance?

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
All times are UTC-05:00 Page 1 of 1