למישהו יש מושג..?

למישהו יש מושג..?

מה לא בסדר בהגדרה של הפונקציה הבונה של המחלקות היורשות? #include <iostream.h> #include <string.h> #include <conio.h> #include <fstream.h> #include <stdlib.h> #include <ctype.h> class nosea{ char fname[20], lname[20]; long id; public: nosea *next; static int n; void show() { cout<<"Name: "<<fname<<" "<<lname<<" ID: "<<id<<endl; } nosea(char fnam[], char lnam[], long idd); ~nosea(); }; class local:public nosea{ long milid; char adress[20]; long tel; public: void show() { cout<<"Militairy ID: "<<milid<<" adress: "<<adress<<" telephone: "<<tel<<endl; } local(long millid, char *adres, long tell); ~local(); }; struct date{ int day,month,year; }; class tour:public nosea{ char count[20]; struct date dat; public: void show() { cout<<"Country: "<<count<<" Date: "<<dat.day<<"/"<<dat.month<<"/"<<dat.year<<endl; } tour(char *coun, int day, int month, int year); ~tour(); }; /*class list{ nosea *head; public: list(char *fnam, char *lnam, long idd) { head = new nosea(char *fnam, char *lnam, long idd) } ~list(); };*/ void klita(); char menu(); void show(); void main() { char ch; fstream nos, tou, loc; nos.open("nos.dat", ios::in|ios::eek:ut); tou.open("tou.dat", ios::in|ios::eek:ut); loc.open("loc.dat", ios::in|ios::eek:ut); while(ch != -1) { ch = menu(); tolower(ch); switch(ch) { case ´n´: klita(); break; case ´e´: show(); break; case ´c´: system("cls"); break; } } } char menu() { char ch; cout<<"New tourist\nEnter date\nClear screen\n Enter choice: "; cin>>ch; return ch; } nosea::nosea(char *fnam, char *lnam, long idd) { strcpy(fname, fnam); strcpy(lname, lnam); id = idd; } local::local(long millid, char *adres, long tell) : nosea(fnam[20], lnam[20], idd) { strcpy(adress, adres); tel = tell; milid = millid; } tour::tour(char *coun, int day, int month, int year) : nosea(*fnam, *lnam, idd) { strcpy(count, coun); dat.day = day; dat.month = month; dat.year = year; }
 

WarLord

New member
חסרה לך הגדרה של

המשתנים ברשימת האתחול. local::local(long millid, char *adres, long tell) : nosea(fnam[20], lnam[20], idd) לא הגדרת את fnam[20], lnam[20], idd.
 

WarLord

New member
תשובה

במחלקת הבסיס הקונסטרקטור כתוב בצורה הבאה: nosea(char fnam[], char lnam[], long idd) כשאתה קורא לו ברשימת האתחול של המחלקה היורשת אתה צריך לספק לו פרמטרים אקטואלים. למשל עבור local: local::local(long millid, char *adres, long tell) : nosea("Boris", "meken hulon", 12345) { . . } כאשר Boris מתאים ל fname meken hulon מתאים ל lname 12345 מתאים ל idd זו התשובה הטכנית. מבחינת תכן אני לא ממש מבין מה רצית לעשות. אם המחלקות היורשות מרחיבות את מחלקת הבסיס אז אתה צריך לקרוא לקונסטרקטור של מחלקת הבסיס עם פרמטרים שאינם קבועים (כמו Boris) כדי שהאובייקט של מחלקת הבסיס שנבנה יכיל מידע אקטואלי/אמיתי.
 
למעלה