Interdependent modules?

Carlos Santander csantander619 at gmail.com
Mon Jun 19 20:08:11 PDT 2006


Jeremy Gibson <jtgibson telus net> escribió:
> I have a pair of modules which need one another's functionality, and I've been
> poring through the documentation on trying to figure out how to get them working
> together, to no avail.  The structure is basically as follows (with unnecessary
> baggage trimmed out):
> 
> gameobject.d
> ============
> import data (for ac_data class)
> class ac_object : ac_data
> 
> data.d:
> =======
> import gameobject (for ac_object class)
> class ac_data
> class ac_location : ac_data
> class ac_region : ac_location
> function ac_region.Contains(ac_location location)
> function ac_region.Contains(ac_object object)
> 
> 
> Naturally, the compiler doesn't like this kind of cross-dependency of modules.
> However, being a total newbie doesn't help me find an answer, so I thought I'd
> resort to the experts.
> 

The only reason why the compiler shouldn't accept it is if you have module ctors 
or static class ctors in both modules. You should try to remove them from one of 
the modules.

> How can I define a Contains() function override for the ac_region class that
> accepts an ac_object as a parameter?  Is it possible to get the
> ac_region.Contains() function to safely operate on an ac_object (which is
> deliberately defined in a different module) without having to remove the
> function from data.d?
> 
> I'd prefer not to define the ac_region functionality in a seperate module
> because it should be a part of the standard suite of data types conferred by the
> "data" module.  I always could define it seperately if absolutely necessary,
> though I'd secretly hate myself... =P
> 
> 

Before reading this I was going to say just that: put ac_data in another file, 
but if you can't, you can't :D

-- 
Carlos Santander Bernal



More information about the Digitalmars-d-learn mailing list