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

  • SEARCH
  • Home
  • 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 7823853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:23:49+00:00 2026-06-02T08:23:49+00:00

I have a question: Say I have originally these classes which I can’t change

  • 0

I have a question:

Say I have originally these classes which I can’t change (let’s say because they’re taken from a library which I’m using):

class Animal_
{
public:
    Animal_();
    int getIdA()
    {
        return idA;
    };
    string getNameA()
    {
        return nameA;
    }
private:
    string nameA;
    int idA;
}

class Farm
{
public :
    Farm()
    {
        sizeF=0;
    }
    Animal_* getAnimal_(int i)
    {
        return animals_[i];
    }
    void addAnimal_(Animal_* newAnimal)
    {
        animals_[sizeF]=newAnimal;
        sizeF++;
    }
    
private:
    int sizeF;
    Animal_* animals_[max];
}

But then I needed a class where I just add couple of fields so I did this:

class PetStore : public Farm
{
public :
    PetStore()
    {
     idF=0;
    };
private:
    int idF;
    string nameF;
}

However, I can’t initialize my derived class. I mean I did this Inheritance so I can add animals to my PetStore but now since sizeF is private how can I do that? I’m thinking maybe in the PetStore default constructor I can call Farm()… so any idea?

  • 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-02T08:23:51+00:00Added an answer on June 2, 2026 at 8:23 am

    The constructor of PetStore will call a constructor of Farm; there’s
    no way you can prevent it. If you do nothing (as you’ve done), it will
    call the default constructor (Farm()); if you need to pass arguments,
    you’ll have to specify the base class in the initializer list:

    PetStore::PetStore()
        : Farm( neededArgument )
        , idF( 0 )
    {
    }
    

    (Similarly, the constructor of PetStore will initialize
    sizeF, by calling the constructor of Farm. The constructor of a class always calls the constructors of
    all of its base classes and all of its members.)

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

Sidebar

Related Questions

I have a question to which I have not found an answer. Let's say
I have a question about how Hibernate persists entity relations. Let's say I have
This is a best practices question Let say, I have a class object, like
I'm developing an iPhone app and have a question about memory management. Let's say
I have a question regarding dependency injection. say i want to create a class
Bit of a beginner question here: Say I have a block of xml: <root>
I have a question about laying out some swing components. Say, I have a
I have a question regarding events in c#. Lets say I have an object
I have a question regarding foreign key in entity framework(EF4). Lets say i have
Or say does 1 denotes white for an RGB image? I have this question

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.