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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:25:56+00:00 2026-05-11T12:25:56+00:00

I am creating a class library with many different options for possible customizations. For

  • 0

I am creating a class library with many different options for possible customizations. For example, you can design your class so that it can perform FeatureX(), or you can design your class so that it can perform FeatureY().

Under normal circumstances, you would simply create an interface IFeatureX with a pure virtual method called FeatureX, and another interface IFeatureY with a pure virtual method called FeatureY. If a class has both FeatureX and FeatureY, it can inherit from both, no problem.

My problem is, what if a function/method requires an object that can perform both FeatureX() and FeatureY()? How do I express a type, in C++ preferably, but an answer in Java could help as well, to ensure that both FeatureX and FeatureY are available?

Do I create another interface IFeatureXY that inherits from IFeatureX and IFeatureY? Okay… if there are only two features I could get away with this. But if there are say… 10 features, the number of possible interfaces becomes massive.

Is there a simple way to do this? I tried solving the problem using C++ templates and delegation but didn’t get too far. I’m hoping there is a simple solution to this, and there probably is one that I just overlooked.

I appreciate any help and advice you guys have.

Thanks.

  • 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. 2026-05-11T12:25:57+00:00Added an answer on May 11, 2026 at 12:25 pm

    If you’re not afraid of using templates, you can make your function a template and use SFINAE to check for the two interfaces:

    template <class T> void my_function(const T& data, typename enable_if_c<     is_convertible<T*, IFeatureX*>::value &&      is_convertible<T*, IFeatureY*>::value>::type*=0) {   ... } 

    This will create a method for every type that extends both feature interfaces (note that the SFINAE trick is not needed for it to work; an unconstrained template would work, but just fail to compile when you pass a type that doesn’t meet the requirements).

    Another possibility is to create an interface IFeatureXY extending both, and use this in the function parameters; this has the drawback that types that do implement both interfaces, but not this joint interface would not be usable with this method.

    Also, you can pass two arguments to the function, one per interface, and require they are pointers to the same object; this is fragile, but could be hardened by making some template class to hold the two pointers – eg. product_type<IFeatureX*, IFeatureY*>, which would be initialized by the single object in question and which would hold the two types.

    In Java, you could probably do the same thing with bounded type variables (if they allow multiple bounds; I’m not sure now).

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

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer There is absolutely no need to use reflection here. So… May 11, 2026 at 2:49 pm
  • added an answer When you add the controls the first time, keep track… May 11, 2026 at 2:49 pm
  • added an answer The problem was caused by early abortion of the foreground… May 11, 2026 at 2:49 pm

Related Questions

I am creating a class library for a CRUD business application. The major categories
In my app, I am creating a series of validation classes to check, for
I am trying to become a good programming citizen through learning more about Dependency
I have a WCF Web Service which is referenced from a class library. After

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.