forward reference hell!

Moritz Warning moritzwarning at web.de
Sat Feb 14 20:20:16 PST 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
> 
> $ cat vector.d #-----------------------------------------------------
> module vector;
> 
> class Vector(E) {
>   E[] data;
> }
> 
> $ cat student.d #-----------------------------------------------------
> module student;
> 
> import vector;
> import teacher;
> 
> // define Student
> class Student {
>   void ask(Teacher teacher) {
>   }
> }
> 
> // define Students
> alias Vector!(Student) Students;
> 
> $ cat teacher.d #-----------------------------------------------------
> 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. :(



More information about the Digitalmars-d mailing list