package.d imports

Lemonfiend lemon at fie.nd
Thu Jan 16 07:46:00 PST 2014


The following behavior seems odd to me. Could anyone explain why 
it works as it does? (Does package.d have a page on dlang.org?)

--- main.d
module main;

void main()
{
	test1();
	test2();
}

void test1()
{
	import pack;

	// works
	foo();

	// works, did not expect it to
	pack.foo();

	// does not work: Error: undefined identifier 'sub'
	//pack.sub.foo();
}

void test2()
{
	import pack.sub;

	// works
	foo();

	// works, even more unexpectedly
	pack.foo();

	// works
	pack.sub.foo();
}

--- package/pack.d
module pack;

public import pack.sub;

--- package/sub.d
module pack.sub;

void foo()
{
	import std.stdio;
	writeln("hello");	
}


More information about the Digitalmars-d-learn mailing list