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 7568739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:59:57+00:00 2026-05-30T14:59:57+00:00

I have a class Grandparent which is provided by a library. I’d like to

  • 0

I have a class Grandparent which is provided by a library. I’d like to define an interface for subclasses of Grandparent, so I created an abstract subclass called Parent:

class Grandparent {
    public:
        Grandparent(const char*, const char*);
};

class Parent : public Grandparent {
    public:
        virtual int DoSomething() = 0;
};

The constructor for Grandparent takes two arguments. I’d like my child class, Child, to also have a constructor with two arguments, and just pass these to the constructor for Grandparent… something like

class Child : public Parent {
    public:
        Child(const char *string1, const char *string2)
        : Grandparent(string1, string2)
        {}

        virtual int DoSomething() { return 5; }
};

Of course, Child’s constructor can’t call its grandparent class’s constructor, only its parent class’s constructor. But since Parent can’t have a constructor, how can I pass these values to the grandparent’s 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-05-30T14:59:59+00:00Added an answer on May 30, 2026 at 2:59 pm

    Parent can certainly have a constructor. It must, if it’s going to call the Grandparent constructor with any parameters.

    There’s nothing forbidding abstract classes from having constructors, destructors, or any other kind of member function. It can even have member variables.

    Simply add the constructor to Parent. In Child, you’ll call the Parent constructor; you can’t “skip a generation” with constructor calls.

    class Parent: public Grandparent
    {
    public:
      Parent(char const* string1, char const* string2):
        Grandparent(string1, string2)
      { }
      virtual int DoSomething() = 0;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a super super (grandparent) abstract bean class calling loadData() method in its
I need to have a class constructor in PHP call its parent's parent's (grandparent?)
I have class A, which exposes an event. an object of class B subscribed
I have class which implements Countable, ArrayAccess, Iterator and Serializable. I have a public
I have class GUI so I can create object like this: GUI g1 =
I have some Django models with a structure similar to this: class Grandparent(models.Model): name
I have class A which has ISerializable implemented for custom serialization. Now i need
I have Class called Person containing to properties, Father and List of Children. I
I have Class which extends JDialog . Have an another JDialog declared inside the
class GrandParent { public virtual void Foo() { ... } } class Parent :

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.