Class Inheritance - matching arguments

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Nov 2007
Posts: 66
Reputation: superjacent is an unknown quantity at this point 
Solved Threads: 3
superjacent's Avatar
superjacent superjacent is offline Offline
Junior Poster in Training

Class Inheritance - matching arguments

 
0
  #1
Mar 17th, 2008
I'm self studying from the book, C++ Primer Plus Fifth Edition, by Stephen Prata. The following relates to Chapter 13, Page 699, Programming Exercise #4. One task is to write the derived class method definitions based upon the given prototypes. The following are the said prototypes.

  1. class Port
  2. {
  3. private:
  4. char *brand;
  5. char style[20]; // i.e. tawny, ruby, vintage
  6. int bottles;
  7. public:
  8. Port(const char *br = "none", const char *st = "none", int b = 0);
  9. Port(const Port &p); // copy constructor
  10. virtual ~Port() { delete [] brand;}
  11. Port & operator=(const Port &p);
  12. Port & operator+=(int b);
  13. Port & operator-=(int b);
  14. int BottleCount() const {return bottles;}
  15. virtual void Show() const;
  16. friend ostream &operator<<(ostream &os, const Port &p);
  17. };
  18.  
  19. class VintagePort : public Port
  20. {
  21. private:
  22. char * nickname; // i.e. The Noble, or Old Velvet, etc.
  23. int year; // vintage year
  24. public:
  25. VintagePort();
  26. VintagePort(const char *br, int b, const char *nn, int y);
  27. VintagePort(const VintagePort &vp);
  28. ~VintagePort() {delete [] nickname;}
  29. void Show() const;
  30. friend ostream & operator<<(ostream &os, const VintagePort & vp);
  31. };
My problem relates to the constructors, lines 8 and 26, displayed again:
  1. Port(const char *br = "none", const char *st = "none", int b = 0);
  2. VintagePort(const char *br, int b, const char *nn, int y);
How can a method definition be correctly written if the argument list has a missing base class argument (as is the case here), which is required for the base class constructor.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: Class Inheritance - matching arguments

 
0
  #2
Mar 17th, 2008
the missing argument appears to be the one to initialize the style member. based on comments in the base class, i guess that you are expected to pass "vintage" as the style for VintagePort .
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 66
Reputation: superjacent is an unknown quantity at this point 
Solved Threads: 3
superjacent's Avatar
superjacent superjacent is offline Offline
Junior Poster in Training

Re: Class Inheritance - matching arguments

 
0
  #3
Mar 17th, 2008
Thanks again. After posting this question, re-reading it, I sort of then realised that the missing argument had to be 'hardcoded' or be a 'string literal' at the definition. Probably the point of the exercise. In any event, it's making me think.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 775 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC