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.

class Port
{
    private:
        char *brand;
        char style[20];     // i.e. tawny, ruby, vintage
        int bottles;
    public:
        Port(const char *br = "none", const char *st = "none", int b = 0);
        Port(const Port &p);            // copy constructor
        virtual ~Port() { delete [] brand;}
        Port & operator=(const Port &p);
        Port & operator+=(int b);
        Port & operator-=(int b);
        int BottleCount() const {return bottles;}
        virtual void Show() const;
        friend ostream &operator<<(ostream &os, const Port &p);
};

class VintagePort : public Port
{
    private:
        char * nickname;            // i.e. The Noble, or Old Velvet, etc.
        int year;                   // vintage year
    public:
        VintagePort();
        VintagePort(const char *br, int b, const char *nn, int y);
        VintagePort(const VintagePort &vp);
        ~VintagePort() {delete [] nickname;}
        void Show() const;
        friend ostream & operator<<(ostream &os, const VintagePort & vp);
};

My problem relates to the constructors, lines 8 and 26, displayed again:

Port(const char *br = "none", const char *st = "none", int b = 0);
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.

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 .

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.