how should I set the constructor in order to inherit the base class?

This is a discussion on how should I set the constructor in order to inherit the base class? within the C++ Programming forums, part of the General Programming Boards category; Hi, I had a base class and two derived classes. I don't know how to set the constructor of the ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    81

    Question how should I set the constructor in order to inherit the base class?

    Hi,

    I had a base class and two derived classes. I don't know how to set the constructor of the 3rd class in order to inherit the base class and 2nd class data members - name, price and life.

    I tried many but incurred many errors.

    Any help?

    Thanks a lot.

    gogo

    #ifndef PRODUCT_H
    #define PRODUCT_H
    #include <iostream>
    #include <string>
    using namespace std;

    //--------Base Class--------------//

    class Product
    {
    private:
    string manufacturer;
    char flag;
    string date;

    protected:
    double price;
    string name;
    int life;

    public:
    Product();

    Product(string na);

    Product(string na, double pr);

    Product(string na, double pr, int li);

    virtual void display()=0;
    };

    //----------------- 1st level derived class----------------//

    class Fruitublic Product
    {
    private:
    string demand;
    string supply;
    double percent;

    public:
    Fruit(){}

    Fruit(string na, double pr, int li):Product(na, pr, li){}

    Fruit(string na, double pr, int li, string de, string su):Product(na, pr, li), demand(de), supply(su){}

    double calpercent(string de, string su);

    double pricechange();

    void display();

    };

    //-------------------- 3rd level derived class----------------//

    class Orangeublic Fruit
    {
    public:
    Orange(){} // ?? How should I set it here for the inheritance of the base class and 2nd class data members?

    Orange(string de, double su){}

    double calpercent(string de, string su);

    double pricechange();

    void display();

    }

    #endif

    ;

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    81
    Sorry, I fixed my problem:

    #ifndef PRODUCT_H
    #define PRODUCT_H
    #include <iostream>
    #include <string>
    using namespace std;

    //--------Base Class--------------//

    class Product
    {
    private:
    string manufacturer;
    char flag;
    string date;

    protected:
    double price;
    string name;
    int life;

    public:
    Product();

    Product(string na);

    Product(string na, double pr);

    Product(string na, double pr, int li);

    //double pricechange();

    virtual void display()=0;
    };

    //----------------- 1st level derived class----------------//

    class Fruitublic Product
    {
    protected:
    string demand;
    string supply;
    double percent;

    public:
    Fruit(){}

    Fruit(string de, string su){}

    Fruit(string de, string su, double per){}

    Fruit(string na, double pr, int li):Product(na, pr, li){}

    Fruit(string na, double pr, int li, string de, string su):Product(na, pr, li), demand(de), supply(su){}

    double calpercent(string de, string su);

    double pricechange();

    void display();

    };

    //-------------------- 3rd level derived class----------------//

    class Orangeublic Fruit
    {
    public:
    Orange(){}

    Orange(string de, string su):Fruit(de, su){}

    Orange(string na, double pr, int li):Fruit(na, pr, li){}

    double calpercent(string de, string su);

    double pricechange();

    void display();

    };




    #endif

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Virtual base class constructor
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 03-24-2008, 03:18 AM
  2. Two conceptual questions
    By AntiScience in forum C++ Programming
    Replies: 3
    Last Post: 11-01-2007, 12:36 PM
  3. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM
  4. Problems w.r.t Virtual Base Class (inheritance)
    By pankajdynamic in forum C++ Programming
    Replies: 1
    Last Post: 04-15-2002, 11:28 AM
  5. Difficulty superclassing EDIT window class
    By cDir in forum Windows Programming
    Replies: 7
    Last Post: 02-21-2002, 05:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21