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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:56:25+00:00 2026-06-09T10:56:25+00:00

Please take a look at my class structure. I think I would like to

  • 0

Please take a look at my class structure. I think I would like to have more fun with inheritance than it is possible.

First there is a base abstract class:

public abstract class PolicyDetailed
{
    internal abstract DataContainer GetActiveAsset();
}

Next there is another abstract class, which is generic:

public abstract class PolicyDetailed<T> : PolicyDetailed where T : DataContainer
{
    internal new abstract T GetActiveAsset();
}

Lastly there is a specific policy class. AccidentContainer inherits from DataContainer:

public class PolicyAccident : PolicyDetailed<AccidentContainer>
{
    internal override AccidentContainer GetActiveAsset()
    {
        return null;
    }
}

During compilation I get the following error:

'PolicyAccident' does not implement inherited abstract member 'PolicyDetailed.GetActiveAsset()'  

I am not sure what modifiers I should use here to get it to work. Maybe I should also write what I would like to achieve: I have a collection of policy objects of different type (e.g. PolicyAccident, PolicyTravel etc.) which inherit from PolicyDetailed with different types of DataContainer (AccidentContainer, TravelContainer etc.). I would like to call “GetActiveAsset” method on each of them without knowing their specific type and referencing them through PolicyDetailed. At the same time I would like each class to return their specific Datacontainer subclass. Is that possible?

  • 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-09T10:56:26+00:00Added an answer on June 9, 2026 at 10:56 am

    The problem is that you can’t override the non-generic method in the same class as you declare any other method with the same signature.

    There are a few options:

    • By far the simplest is to give the two methods different names. Then you can give an implementation in PolicyDetailed<T> which just delegates to the new abstract method:

      public abstract class PolicyDetailed
      {
          internal abstract DataContainer GetActiveAsset();
      }
      
      public abstract class PolicyDetailed<T> : PolicyDetailed where T : DataContainer
      {
          internal abstract T GetActiveAssetGeneric();
      
          internal override DataContainer GetActiveAsset()
          {
              return GetActiveAssetGeneric();
          }
      }
      
      public class PolicyAccident : PolicyDetailed<AccidentContainer>
      {
          internal override AccidentContainer GetActiveAssetGeneric()
          {
              return null;
          }    
      }
      
    • You could introduce another level of inheritance, introducing a new method name just for bridging purposes. This is pretty ugly:

      public class DataContainer {}
      public class AccidentContainer : DataContainer{}
      
      public abstract class PolicyDetailed
      {
          internal abstract DataContainer GetActiveAsset();
      }
      
      // This only exists to satisfy the base class abstract member,
      // but at the same time allowing PolicyDetailed<T> to introduce
      // a new member with the same name.
      public abstract class PolicyDetailedBridge<T> : PolicyDetailed
          where T : DataContainer
      {
          protected abstract T GetActiveAssetGeneric();
      
          internal override DataContainer GetActiveAsset()
          {
              return GetActiveAssetGeneric();
          }
      }
      
      public abstract class PolicyDetailed<T> : PolicyDetailedBridge<T>
          where T : DataContainer
      {
          protected sealed override T GetActiveAssetGeneric()
          {
              // Call the *new* abstract method. Eek!
              return GetActiveAsset();
          }
      
          internal abstract new T GetActiveAsset();
      }
      
      public class PolicyAccident : PolicyDetailed<AccidentContainer>
      {
          internal override AccidentContainer GetActiveAsset()
          {
              return null;
          }            
      }
      
    • You could make the non-generic PolicyDetailed class an interface instead, and use explicit interface implementation to declare a new abstract method and still implement the interface.

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

Sidebar

Related Questions

Please take a look at this screenshot first: I would like to move the
can someone take a look at this please http://jsfiddle.net/bloodygeese/ecscY/56/ it looks like I have
Please take a look at this code: template<class T> class A { class base
Please take a look at my simple three-methods Service class that streams audio and
Would someone please take a look at the following code fragments (all from one
Please take a look at the test class below. I am trying to do
Please take a look on the following example: class Base { protected: int m_nValue;
Please take a look at following code: public class SomeEntity { public int Id
Please take a look at the code. It shouldn't take long to have a
Please take a look at this code: class Foo { public $barInstance; public function

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.