Re: Importing, and visibility

2009-10-11 Thread Jarrett Billingsley
On Sun, Oct 11, 2009 at 3:05 PM, Matt  wrote:
> In C++ I see a lot of defining an enum, struct, or other values before 
> #including another header which then uses these values. I understand why this 
> works in C++, but does the same thing work in D? I'd assume not, since the 
> import mechanism is a little more advanced than C++'s "copy this file into 
> this location".

Not.. really. If module A imports module B, B does not see A's symbols at all.

However, it's possible to use mixins of various types to emulate
this. For instance, module B could define all of its members inside a
template, like so:


module B;

template BMembers()
{
some declarations
more declarations
}


Then in module A:


module A;
import B;

// define structs and stuff
mixin BMembers; // mixes in B's definitions into A, and they use A's symbols


You could also use the 'mixin(import("somefile"))' idiom at module
scope in A, but that's a bit hacky, and won't get you as decent error
messages.


Importing, and visibility

2009-10-11 Thread Matt
In C++ I see a lot of defining an enum, struct, or other values before 
#including another header which then uses these values. I understand why this 
works in C++, but does the same thing work in D? I'd assume not, since the 
import mechanism is a little more advanced than C++'s "copy this file into this 
location".