forward reference hell!

Chris R Miller lordsauronthegreat at gmail.com
Sun Feb 15 15:53:14 PST 2009


To stop a forward-reference problem you need to declare the type, but 
not implement it.  Eg:

$ cat vector.d #-----------------------------------------------------
 > module vector;
 >
 > class Vector(E) {
 >   E[] data;
 > }
 >
 > $ cat student.d #-----------------------------------------------------
 > module student;
 >
 > import vector;

class 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;
 > }

It is not necessary to smash them all into one file.



More information about the Digitalmars-d mailing list