// student.hh const int MAX_SKZ = 5; struct Student { ... }; struct Student_Mult { ... }; struct Student2 { ... }; void Copy_Student2(Student2& lhs, const Student2& rhs); |
Die neue Funktion Copy_Student2 wird in student.cc (siehe student.cc) definiert, wobei der Funktionskörper aus Ex643-correct.cc kopiert wurde.
// student.cc #include <strings.h> #include "student.hh" void Copy_Student2(Student2& lhs, const Student2& rhs) { lhs = rhs; // Allocate memory and copy data lhs.pname = new char[strlen(rhs.pname)+1]; strcpy(lhs.pname,rhs.pname); lhs.pvorname = new char[strlen(rhs.pvorname)+1]; strcpy(lhs.pvorname,rhs.pvorname); return; } |
Da die Struktur Student2 verwendet wird, muß auch das Headerfile student.hh in student.cc eingebunden werden. Die neue Funktion Copy_Student2 kann nunmehr im Hauptprogramm Ex752.cc (siehe Ex752.cc) zum Kopieren einer Struktur benutzt werden. Das Hauptprogramm benötigt dafür natürlich wieder das Headerfile student.hh.
Das Kommando
LINUX> g++ Ex752.cc student.cc
erzeugt schlußendlich das Programm a.out.