Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8936925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:19:13+00:00 2026-06-15T10:19:13+00:00

My professor gave the following code to show an example of inheritance: //Base class

  • 0

My professor gave the following code to show an example of inheritance:

//Base class
class Inventory {
    int quant, reorder; // #on-hand & reorder qty
    double price; // price of item
    char * descrip; // description of item
public:
    Inventory(int q, int r, double p, char *); // constructor
    ~Inventory(); // destructor
    void print();
    int get_quant() { return quant; }
    int get_reorder() { return reorder; }
    double get_price() { return price; }
};
Inventory::Inventory(int q, int r, double p, char * d) : quant (q), reorder (r), price (p)
{
    descrip = new char[strlen(d)+1]; // need the +1 for string terminator
    strcpy(descrip, d);
} // Initialization list



//Derived Auto Class
class Auto : public Inventory {
    char *dealer;
public:
    Auto(int q, int r, double p, char * d, char *dea); // constructor
    ~Auto(); // destructor
    void print();
    char * get_dealer() { return dealer; }
};
Auto::Auto(int q, int r, double p, char * d, char * dea) : Inventory(q, r, p, d) // base constructor
{
    dealer = new char(strlen(dea)+1); // need +1 for string terminator
    strcpy(dealer, dea);
}

I was confused line “Auto::Auto(int q, int r, double p, char * d, char * dea) : Inventory(q, r, p, d)”, what is the definition “Inventory(q, r, p, d)” doing. Similarly
in the line “Inventory::Inventory(int q, int r, double p, char * d) : quant (q), reorder (r), price (p)” I’m not sure what he is doing with quant (q), reorder (r), price (p). Are these the same variables that were defined in class as int quant, reorder and double price? If so, why did he have to use in the constructor. And why/how did he use a constructor from a base class to help define “Auto” class constructor.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:19:14+00:00Added an answer on June 15, 2026 at 10:19 am

    He is using “initialization lists”.

    He is calling the base class constructor. Auto::Auto(int q, int r, double p, char * d, char * dea) : Inventory(q, r, p, d) defines a constructor for the Auto class which calls the parametrized constructor of the Inventory. The parameterized constructor needs to be called because Auto is inheriting from Inventory and Inventory defines a parameterized constructor. C++ specifies that if you define a parameterized constructor, the default constructor is overridden and the only way you can instantiate an object of that class or any sub-class is by calling the parametrized constructor (or by defining an alternate default constructor).

    In the case of Inventory::Inventory(int q, int r, double p, char * d) : quant (q), reorder (r), price (p), he is initializing the fields quant, reorder and price with the values q, r and p respectively. This is actually a shorthand and you can instead assign the values in the constructor body (unless the member is a constant).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My professor gave an example located on slide 3 of this pdf : can
My professor gave us some code in a Microsoft Word document and said it
I'm a student of computer science in Germany. My professor gave use the following
I saw the following example on the internet: public class TwoThreads { public static
My professor gave me the following definition of Shell Sort. I've included the Bubble
My professor gave my class an assignment today based on object oriented programming in
My Professor gave us this class and told us that it won't compile. He
My professor recently gave my class an assignment and I need help finding the
I'm presenting a problem my professor showed in class, with my O(n*log(n)) solution: Given
I am doing an assignment for an information systems class and the professor decided

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.