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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:26:20+00:00 2026-05-27T02:26:20+00:00

I have 4 classes organized under Multiple inheritance rhomboidal scheme. BASE / \ /

  • 0

I have 4 classes organized under Multiple inheritance rhomboidal scheme.

             BASE
             /  \
            /    \
        Deriv1  Deriv2
            \    /
             \  /
             Final

I have for each class “ShowXXXX()” methods (for example), where ‘XXXX’ is the name of the class.

When i call “ob.ShowFinal()” method it prints:

  • Final’s fields,
  • Deriv1’s fields,
  • Base’s fields,
  • Deriv2’s fields,
  • Base’s fields

The problem is that i want to escape printing Base’s fields second time.
But, there is an paradigm: cause when i call “ob.ShowDeriv2()” it should be printed:

  • Deriv2’s fields,
  • Base’s fields

and when i call “ob.ShowDeriv1()” it should be printed:

  • Deriv1’s fields,
  • Base’s fields

My code:

// multipleInheritance.cpp : Defines the entry point for the console application.
//

//Summary:
//      
//      Mmb - member
//      Prm - parameter
//      b - Base
//      i1, i2 - Intermediate1, Intermediate2
//      f - final

class Base
{
    int bMmb;

public:
    Base(int);
    void ShowBase();
};

Base::Base (int bPrm)
{
    bMmb = bPrm;
}

void Base::ShowBase()
{
    cout << "Showing Base fields" << endl;
    cout << "bMmb = " << bMmb << endl; 
    cout << "----------------------------" << endl << endl;
}

class Intermediate1 : public Base
{
    int i1Mmb;

public:
    Intermediate1(int, int);
    void ShowIntermediate1();
};

Intermediate1::Intermediate1(int bPrm, int i1Prm):Base(bPrm)
{
    i1Mmb = i1Prm;
}

void Intermediate1::ShowIntermediate1()
{
    cout << "Showing Intermediate1 fields" << endl;
    cout << "i1Mmb = " << i1Mmb << endl;
    ShowBase();
}

class Intermediate2 : public Base
{
    int i2Mmb;

public:
    Intermediate2(int, int);
    void ShowIntermediate2();
};

Intermediate2::Intermediate2(int bPrm, int i2Prm):Base(bPrm)
{
    i2Mmb = i2Prm;
}

void Intermediate2::ShowIntermediate2()
{
    cout << "Showing Intermediate2 fields" << endl;
    cout << "i2Mmb = " << i2Mmb << endl;
    ShowBase();
}

class Final : public Intermediate1, public Intermediate2
{
    int fMmb;

public:
    Final(int, int, int, int);
    void ShowFinal();
};

Final::Final(int bPrm, int i1Prm, int i2Prm, int fPrm): Intermediate1(bPrm, i1Prm), Intermediate2(bPrm, i2Prm)
{
    fMmb = fPrm;
}

void Final::ShowFinal()
{
    cout << "Showing Final fields" << endl;
    cout << "fMmb = " << fMmb << endl;
    ShowIntermediate1();
    ShowIntermediate2();
}

void main()
{
    Base t(1);
    t.ShowBase();

    Intermediate1 u1(2, 31);
    u1.ShowIntermediate1();

    Intermediate2 u2(4, 51);
    u2.ShowIntermediate2();

    Final v(6, 71, 72, 8);
    v.ShowFinal();
}

Thank you for help!

  • 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-27T02:26:21+00:00Added an answer on May 27, 2026 at 2:26 am

    There are very little constraints in your question, so this should work.

    Change the declaration in Intermediate1 (and 2) to

    public:
        void ShowIntermediate1(bool printBase = true);
    

    And in the implementation:

    ...
    if (printBase)
     ShowBase();
    

    Then in ShowFinal():

    ShowIntermediate1(true);
    ShowIntermediate2(false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have classes of Type A and B: public class A { public
I have some classes layed out like this class A { public virtual void
I have two classes, and want to include a static instance of one class
I have some test case classes organized in directories foo_tests foo_tests1.py foo_tests2.py ... bar_tests
Let's say I have multiple projects organized as commonlib superorg org1 suborg11 suborg12 org2
I have a C# class library that contains several resources files organized in folders.
I have classes that store data, and methods to go get data for individual
I have classes that are named exactly the same across different plug-ins that I
I have classes which have automatic properties only like public customerName {get; set;}. They
I have classes that are needed in both my web service and my server.

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.