C++ How send multiple values to two upper superclass? -


first of think factory system. create date class hold person's birthday , initial date work.e.g , have person class holds information person name, surname etc. , have department class , want initialize information person , department id , department name(name, surname..,birthday, initial work date ). created array in type of person in department header file. problem how can write deparment construct initialize attributes. no problem name, surname... date class requires 3 parameter. how can send there parameter other parameters department class?

class date { int gun,ay,yil;  public:  int getday()const; int getmonth()const; int getyear()const;  void set_day(int); void setmonth(int); void setyear(int);      date();     date(int,int,int);     virtual ~date();  } class deparment {       int     bolumid;     string  bolumname;     static const int maxkisi = 10;     person *personarray = new person[maxkisi];     static int counter;     date datex,datey;     public:     int     getbolumid()const;     string  getbolumname()const;     int     gettemelmaas()const;     person    getpersonarray()const;      void setbolumid(int);     void setbolumname(string);     void setkisiarray(string,string,int,int);          bolum();         bolum(string,string,int,date,date,int,string);         virtual ~bolum();  } 

there 2 ways go doing it:

  • take date object in constructor of class, or
  • take date's parameters in constructor of class.

each of 2 approaches has pluses , minuses:

the first approach hides parameters taken date caller, caller can construct date in way wishes:

person(const string& _name, const string& _surname, const date& _dob) :   name(_name), surname(_surname), dob(_dob) { } 

the second approach lets hide date caller, if class not expose date externally visible attribute. in other words, can hide fact class uses date, letting switch away implementation if need in future.

person::person(const string& _name, const string& _surname, int dd, int mm, int yy) :  name(_name), surname(_surname), dob(date(mm, dd, yy) { } 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -