www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Importing, and visibility

reply Matt <webwraith fastmail.fm> writes:
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".
Oct 11 2009
parent Jarrett Billingsley <jarrett.billingsley gmail.com> writes:
On Sun, Oct 11, 2009 at 3:05 PM, Matt <webwraith fastmail.fm> wrote:
 In C++ I see a lot of defining an enum, struct, or other values before #i=
ncluding 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 a= ll. Howeeeeever, 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 symbol= s ---- 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.
Oct 11 2009