namespace (for export)

spir denis.spir at gmail.com
Thu Nov 25 11:31:01 PST 2010


On Thu, 25 Nov 2010 19:28:13 +0100
"Simen kjaeraas" <simen.kjaras at gmail.com> wrote:

> > You seems to take it for granted that I cannot write:
> > 	auto myExportedSymbol = new T();
> > 	...
> > 	myExportedSymbol.i = 1;
> > but for me there is no obvious reason why D refuses that, and accepts
> > 	T myExportedSymbol;
> > 	static this () {
> > 	   auto myExportedSymbol = new T();
> > 	   ...
> > 	   myExportedSymbol.i = 1;
> > 	}
> > It's the same thing, from my point of view: when I import the module, I  
> > get the symbol correctly defined. I don't get why a module needs a  
> > constructor: why else has it a top-level?  
> 
> The reason for this is partly historical (C does it this way), but more
> importantly, practical. This way it is obvious what code will be executed
> at which time, and code is not as easily 'hidden' between type and
> variable declarations.

Thank you, Simen, I get it better. I have a solution with static this anyway, even if not completely satisfying. Simply tried  to understand better the whys and hows.
(And sorry all for the somewhat frustrated tone of a few posts by me.)


Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com



More information about the Digitalmars-d-learn mailing list