digitalmars.D - forward reference hell!
- sa (38/38) Feb 14 2009 Since there are more people here, I fwd the post here to get advice.
- Moritz Warning (7/57) Feb 14 2009 fwiw, I was porting some pre D1.0 D program (not mine) to D1.0 today
- hehe (6/12) Feb 14 2009 Haha, you are going thru the same route as I did years ago, and when I e...
- Chris R Miller (5/25) Feb 15 2009 To stop a forward-reference problem you need to declare the type, but
Since there are more people here, I fwd the post here to get advice. =============================================== http://d.puremagic.com/issues/show_bug.cgi?id=2666 module vector; class Vector(E) { E[] data; } module student; import vector; import teacher; // define Student class Student { void ask(Teacher teacher) { } } // define Students alias Vector!(Student) Students; module teacher; import student; class Teacher { Students students; } =============================================== $ dmd -c student.d teacher.d(6): Error: forward reference to 'Vector!(Student)' teacher.d(6): Error: Students is used as a type teacher.d(6): variable teacher.Teacher.students voids have no value =============================================== sure I know if I do: $ dmd -c vector.d teacher.d student.d all the three files can be compiled without error. But my question is: why can't file be individually compiled? I think I have the most natural/logical organization of files; if you move the 'Students' alias around, it could get compiled, but what's wrong with my current organization?
Feb 14 2009
On Sun, 15 Feb 2009 01:19:54 +0000, sa wrote:Since there are more people here, I fwd the post here to get advice. =============================================== http://d.puremagic.com/issues/show_bug.cgi?id=2666 module vector; class Vector(E) { E[] data; } module student; import vector; import teacher; // define Student class Student { void ask(Teacher teacher) { } } // define Students alias Vector!(Student) Students; module teacher; import student; class Teacher { Students students; } =============================================== $ dmd -c student.d teacher.d(6): Error: forward reference to 'Vector!(Student)' teacher.d(6): Error: Students is used as a type teacher.d(6): variable teacher.Teacher.students voids have no value =============================================== sure I know if I do: $ dmd -c vector.d teacher.d student.d all the three files can be compiled without error. But my question is: why can't file be individually compiled? I think I have the most natural/logical organization of files; if you move the 'Students' alias around, it could get compiled, but what's wrong with my current organization?fwiw, I was porting some pre D1.0 D program (not mine) to D1.0 today and run into the same problem. I wasted >2 hours to play with dependencies just to end up with no solution. Looks like I have to pull ~8 files into one just to make it compile, but ruin code separation. :(
Feb 14 2009
fwiw, I was porting some pre D1.0 D program (not mine) to D1.0 today and run into the same problem. I wasted >2 hours to play with dependencies just to end up with no solution. Looks like I have to pull ~8 files into one just to make it compile, but ruin code separation. :(Haha, you are going thru the same route as I did years ago, and when I eventually put them all into one file (plus generated code), and make the compiler happy, the linker won't link it because there are more than 16,000 fixups in one object file, see the linker bug: http://d.puremagic.com/issues/show_bug.cgi?id=424 I have to say: good luck!
Feb 14 2009
To stop a forward-reference problem you need to declare the type, but not implement it. Eg:module vector; class Vector(E) { E[] data; } module student; import vector;class Teacher;// define Student class Student { void ask(Teacher teacher) { } } // define Students alias Vector!(Student) Students; module teacher; import student; class Teacher { Students students; }It is not necessary to smash them all into one file.
Feb 15 2009