Tuesday, 15 July 2014

C++ Inheritance Default Constructor in Derived Class Issue -



C++ Inheritance Default Constructor in Derived Class Issue -

i'm having issues inheritance. have included 2 different classes i'm working (workticket & extendedworkticket). extendedworkticket should using fellow member variables of workticket, why have used them protected.

my issue comes in when seek create default constructor extendedworkticket. error telling me extendedworkticket doesn't have field names [...] (all except myisopen).

i know can replace fellow member variables workticket(1, "", 1, 1, 2014, "") in constructor, changes functionality calling parameterized constructor workticket , tries validate them using setters, shouldn't doing.

i need create blank workticket (with myisopen member), workticket's default constructor does.

class workticket { public: /*************************************************************************** * default , parameterized constructor(s). * if parameters not specified, set work ticket number zero, * work ticket date 1/1/2000, , other attributes empty * strings. ***************************************************************************/ workticket() : myticketnumber(0), myclientid(""), mydate(1, 1, 2014), mydescription ("") { } workticket(int ticketnumber, string clientid, int day, int month, int year, string description); /*************************************************************************** * re-create constructor * initializes new workticket object based on existing workticket * object. ***************************************************************************/ workticket(const workticket& original); /*************************************************************************** * setworkticket() * mutator method set attributes of object * parameters long parameters valid. of parameters * must valid in order of attributes change. validation * rules explained work ticket number , date. client number * , description must @ to the lowest degree 1 character long. if no problems * detected, homecoming true. otherwise homecoming false. ***************************************************************************/ bool setworkticket(int ticketnumber, string clientid, int day, int month, int year, string description); /*************************************************************************** * showworkticket( ) * accessor method display object's attributes neatly in * console window. ***************************************************************************/ virtual void showworkticket() const; // accessor /*************************************************************************** * attribute sets/gets. * include set (mutator) , (accessor) method each attribute. ***************************************************************************/ // ticket number void setticketnumber(int ticketnumber); int getticketnumber() const {return myticketnumber;} // client id void setclientid(string clientid) {myclientid = clientid;} string getclientid() const { homecoming myclientid;} // decsription void setdescription(string description) { mydescription = description; } string getdescription() const { homecoming mydescription; } // date void setdate(int day, int month, int year); const mydate& getdate() const { homecoming mydate; } /*************************************************************************** * operators (lab 3). * include set (mutator) , (accessor) method each attribute. ***************************************************************************/ workticket& operator=(const workticket& original); // assignment operator string () const; // (string) bool operator==(const workticket& original); // equality friend ostream& operator<<(ostream& out, const workticket& ticket); // output friend istream& operator>>(istream& in, workticket& ticket); // input protected: /*************************************************************************** * private attributes. object of class workticket has next * private attributes. ***************************************************************************/ int myticketnumber; // work ticket number - whole, positive number. string myclientid; // client id - alpha-numeric code assigned client. mydate mydate; // work ticket date - date workticket created string mydescription; // issue description - description of issue client having. }; // end of workticket class

and inheriting kid class:

/*************************************************************************** * lab 4 inheritance class - extendedworkticket * ***************************************************************************/ class extendedworkticket : public workticket { public: extendedworkticket() : myticketnumber(0), myclientid(""), mydate(1, 1, 2014), "", myisopen(true) { } extendedworkticket(int ticketnumber, string clientid, int day, int month, int year, string description, bool isopen) : workticket(ticketnumber, clientid, day, month, year, description) {}; bool getisopen() const { homecoming myisopen; } bool setworkticket(int ticketnumber, string clientid, int day, int month, int year, string description, bool isopen = true); void showworkticket() const override; void closeticket() { myisopen = !myisopen; } friend ostream& operator<<(ostream& out, const extendedworkticket& ticket); // output private: bool myisopen; }; // end of extendedworkticket

extendedworkticket::extendedworkticket() : #if defined(optional) workticket(), #endif #if defined(erroneous) myticketnumber(0), myclientid(""), mydate(1, 1, 2014), "", // incidentally, literal bad syntax, it's not assigned #endif myisopen(true) { }

remove initializations of base-class members; handled base-class constructor. don't need explicitly phone call out base of operations constructor, can if think that's clearer.

c++ inheritance default-constructor

No comments:

Post a Comment