943,871 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 1110
  • C++ RSS
Mar 17th, 2008
0

Class Inheritance - matching arguments

Expand Post »
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.

cpp Syntax (Toggle Plain Text)
  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:
cpp Syntax (Toggle Plain Text)
  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.
Reputation Points: 11
Solved Threads: 3
Junior Poster in Training
superjacent is offline Offline
66 posts
since Nov 2007
Mar 17th, 2008
0

Re: Class Inheritance - matching arguments

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 .
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006
Mar 17th, 2008
0

Re: Class Inheritance - matching arguments

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.
Reputation Points: 11
Solved Threads: 3
Junior Poster in Training
superjacent is offline Offline
66 posts
since Nov 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: abnormal
Next Thread in C++ Forum Timeline: Linked Lists Database...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC