//Perhaps, Friend is vc++6.0 heart forever pain, for this bug I always very mind.
Note: This procedure does not work in the vc++6.0, in the VS2008 is possible.
#include <iostream>#include<string>using namespacestd;classStudent;//Advance Citation Statement//declaring the teacher classclassTeacher { Public: Teacher () {} Teacher (intIstringSCharCintt=0): num (i), name (s), sex (c), Theachyears (t) {} Teacher (Student); Friend Ostream&operator<< (ostream& out,teacher&te);Private: intnum; stringname; CharSex//f/m intTheachyears;};//declaring the Student classclassStudent { Public: Student () {} Student (intIstringSCharCintg=0): num (i), name (s), sex (c), Grade (g) {} friend Teacher::teacher (Student); Friend Ostream&operator<< (ostream& out,student&St);Private: intnum; stringname; CharSex//f/m intgrade;};//Note: According to the Convention, we prefer to write the implementation of the member function directly before the declaration of the class.//However, the implementation of the constructor cannot be written before the student class declaration,
Because it uses members of the student class, the advance reference declaration will not work here Teacher::teacher (Student st) {num=St.num; Name=St.name; Sex=St.sex; Theachyears=0; }//<< of heavy Duty teacher class
Note: The implementation of this constructor cannot be written before the student class declaration for the same reason asostream&operator<< (ostream& out,teacher&te) { out<<"num="<<te.num<<","<<"name="<<te.name<<","<<"sex="<<te.sex<<","<<"theachyears="<<te.theachYears<<Endl; return out;}//<< of heavy duty student classostream&operator<< (ostream& out,student&St) { out<<"num="<<st.num<<","<<"name="<<st.name<<","<<"sex="<<st.sex<<","<<"grade="<<st.grade<<Endl; return out;}intMain () {Student s (1,"Xiaoer",'F',2); cout<<s; Teacher T=Teacher (s); cout<<T; return 0;}
Pre-referential declaration considerations for classes in C + +