digitalmars.D.learn - Problem with imports in class hierarchy
- Marco Falda (29/29) Apr 26 2005 I find a strange error when trying to compile the simple class hierarchy
- Manfred Nowak (10/12) Apr 26 2005 [...]
- Marco Falda (6/12) Apr 27 2005 I re-checked the code: on WinXP Home SP2 my DMD compiler, version 0.121 ...
- Manfred Nowak (7/11) Apr 27 2005 It is both working:
- Jarrett Billingsley (6/9) Apr 27 2005 You can, but it's bad practice. Whenever making modules that will be
I find a strange error when trying to compile the simple class hierarchy reported below, in particular I am not able to compile A11.d nor A2.d; the compiler tells me: "A1.d(3): import A1.A conflicts with A2.A at A2.d(3)". Notice that I need the class A both in A1 and A2 (in C++ this could be declared as a virtual base class); in my opinion the problem is in A11 (in fact is the class that "glues" all the code). What is the problem? How can I fix it maintaining the hierarchy? /* file: A.d */ module A; class A {} --------------- /* file: A1.d */ module A1; private import A; class A1 : A {} --------------- /* file: A11.d */ module A11; private import A1; private import A2; // needed by A11 class A11 : A1 { this(A i) {} } --------------- /* file: A2.d */ module A2; private import A; private import A11; // needed by A2 class A2 : A {}
Apr 26 2005
Marco Falda <Marco_member pathlink.com> wrote: [...]"A1.d(3): import A1.A conflicts with A2.A at A2.d(3)"[...]this(A i) {}[...] The reported error message is not reproducible by your example. The `A' in the parameter list of the constructor is out of scope, but replacing it by `this(A1 i) {}' clears all error messages. -manfred
Apr 26 2005
The reported error message is not reproducible by your example. The `A' in the parameter list of the constructor is out of scope, but replacing it by `this(A1 i) {}' clears all error messages. -manfredI re-checked the code: on WinXP Home SP2 my DMD compiler, version 0.121 (I think, in any case the latest on the site), gives me that error. Anyway, thank you very much for your help, I just added "private import A" in A11.d and now it is all right. I am wondering however why it is not possible to import module A through module A1 in A11 by using a simple "import A" (in A1).
Apr 27 2005
Marco Falda <Marco_member pathlink.com> wrote: [...]I just added "private import A" in A11.d and now it is all right. I am wondering however why it is not possible to import module A through module A1 in A11 by using a simple "import A" (in A1).It is both working: - in a1.d "private import a;" and in a11.d "private import a, a1;" or - in a1.d "import a;" and in a11.d "private import a1;" -manfred
Apr 27 2005
"Marco Falda" <Marco_member pathlink.com> wrote in message news:d4nime$j36$1 digitaldaemon.com...I am wondering however why it is not possible to import module A through module A1 in A11 by using a simple "import A" (in A1).You can, but it's bad practice. Whenever making modules that will be imported, always use private import to import other modules into them. Otherwise, it's very easy to pollute the namespace with names you don't need.
Apr 27 2005