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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:55:28+00:00 2026-05-19T13:55:28+00:00

Assume I have the following class-hierarchy in C++: class AbstractBaseClass { public: // Note:

  • 0

Assume I have the following class-hierarchy in C++:

class AbstractBaseClass
{
public:
    // Note:  Class is completely abstract! No data!
    AbstractBaseClass() {}
    virtual ~AbstractBaseClass() {}
    virtual std::string definedInVirtual() = 0;
    virtual std::string definedInDerived() = 0;
};

class Virtual : public virtual AbstractBaseClass
{
public:
    Virtual() {}
    virtual ~Virtual() {}

    std::string definedInVirtual()
    {
        return "definedInVirtual";
    }
};

class DerivedA : public Virtual
{
public:
    DerivedA() {}
    virtual ~DerivedA() {}

    std::string definedInDerived()
    {
        return "definedInDerivedA";
    }
};

class DerivedB : public Virtual
{
public:
    DerivedB() {}
    virtual ~DerivedB() {}

    std::string definedInDerived()
    {
        return "definedInDerivedB";
    }
};

In this case, calling definedInVirtual() on either DerivedA or DerivedB, the definition of definedInVirtual() on Virtual is called, via cross-delegation. This is, then, a form of code reuse.

What are the drawbacks to this method? Is there a better way to achieve code reuse in this situation?

EDIT:

The main reason I ask is there was a very large class that someone had developed with the plan of code reuse via inheritance (he since regrets doing this, but the class is large) that was super-classed by a new ABC due to adding a decorator derived from the new ABC to the object hierarchy. I need to add methods to the new ABC that need to be handled by the DerivedA and DerivedB, and for the decorator to handle via calling the internal instance of the ABC. My idea is to use the above technique…

  • 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-19T13:55:29+00:00Added an answer on May 19, 2026 at 1:55 pm

    Code re-use should be implemented through composition, not inheritance. Virtual inheritance is slow and extremely messy and should be avoided in nearly all designs.

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

Sidebar

Related Questions

Let's assume we have the following class: public class tx_fct { int _ok; public
Assume I have a class foo, and wish to use a std::map to store
I have a structure that looks following Class TreeNode { public TreeNode Parent {
In Java, assume I have the following class Container that contains a list of
When writing GUIs, I've frequently come over the following problem: Assume you have a
Assume I have a function template like this: template<class T> inline void doStuff(T* arr)
Assume I have a form class SampleClass(forms.Form): name = forms.CharField(max_length=30) age = forms.IntegerField() django_hacker
Assume we have a method like this: public IEnumerable<T> FirstMethod() { var entities =
I have a UIViewController subclass called TripViewController. This class has the following method: -
I have the following tableviewdelegate: private class TableViewDelegate : UITableViewDelegate { private DaysViewController _dvc;

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.