Calling functions from other files/modules

tcak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jan 6 22:15:50 PST 2016


On Wednesday, 6 January 2016 at 23:12:27 UTC, Namal wrote:
> On Wednesday, 6 January 2016 at 23:06:38 UTC, Adam D. Ruppe 
> wrote:
>> On Wednesday, 6 January 2016 at 23:00:43 UTC, Namal wrote:
>>> I just tried to import one module with a main into another, 
>>> but I get this:
>>
>> You can't have two mains, but you can import a module with 
>> main from another module without one.
>
> How can I produce a program file from that module which has no 
> main but uses some functions from main module?

I think the below example clarifies everything.

entry.d
=======

module project.entry;

import std.stdio;
import project.other;

void bark(){
	writeln("Woof");
}

void main(){
	project.other.callbark();	
}




other.d
=======

module project.other;

import project.entry;

void callbark(){
	project.entry.bark();
}



More information about the Digitalmars-d-learn mailing list