luke1985
luke1985

Reputation: 2354

Same module name across multiple files

I don't know if it is even possible: I want to span a module across multiple source files so that I dont have to put every class in a module to one file. So I have two files named "FileA.d" , "FileB.d" , and I want them both to start with a module name: "module amodule"

The problem is later, when I want to import it, I dont know even how.

doing "import FileA" yields an error:

 "module amodule from file FileA.d must be imported as module 'amodule' "

I cant really figure out what this means as the documentation doesnt mention anything about this. So my question is - is it possible and , if yes - how to achieve this?

Thank you in advance.

Upvotes: 3

Views: 223

Answers (2)

DejanLekic
DejanLekic

Reputation: 19797

What you want is not easy for a good reason. Module level access solves C++ friend hell. If you come from the C++ world - think that all classes within a module are friends. It is a language design decision, and a pretty damn good one, IMHO.

Read this section: http://dlang.org/cpptod.html#friends

In short: tightly coupled classes (friends in the C++ world) should be inside the same module.

D is a modular programming language, keep that in mind as this makes it different than C++ or Java.

Upvotes: 2

ratchet freak
ratchet freak

Reputation: 48216

a better way would be to create a module amodule and have that public import FileA, FileB;

Upvotes: 2

Related Questions