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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:04:47+00:00 2026-05-23T08:04:47+00:00

I wish to inherit from a set of classes contained in a boost mpl::vector.

  • 0

I wish to inherit from a set of classes contained in a boost mpl::vector. Is this possible?

Specifically, I wish to extend test for arbitrary many template parameters, passed as a mpl::vector.

template<class T>
struct Slice
{
public:
  virtual void foo(T v) const = 0;
};

struct A{};
struct B{};

template <class T1, class T2>
struct test : public Slice<T1>, public Slice<T2>
{
  void foo(T1 a) const {std::cout<<"A"<<std::endl;}
  void foo(T2 b) const {std::cout<<"B"<<std::endl;}
};

If I know there are only two parameters then I can simply write:

template <class mpl_vector_t >
struct test : public Slice<typename mpl::at<mpl_vector_t,mpl::int_<0> >::type >, 
          public Slice<typename mpl::at<mpl_vector_t,mpl::int_<1> >::type >
{
  typedef typename mpl::at<mpl_vector_t,mpl::int_<0> >::type T1;
  typedef typename mpl::at<mpl_vector_t,mpl::int_<1> >::type T2;

  void foo(T1 a) const {std::cout<<"A"<<std::endl;}
  void foo(T2 b) const {std::cout<<"B"<<std::endl;}
};

Is is possible to do this for an arbitrary mpl::vector?

My test program looks like so:

int
main  (int ac, char **av)
{
  A a;
  B b;
  // test<A,B> t; //original
  test<mpl::vector<A,B> > t;  //mpl::vector with 2 elements
  Slice<A>* Sa = &t;
  Slice<B>* Sb = &t;
  Sa->foo(a);
  Sb->foo(b);
}
  • 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-23T08:04:47+00:00Added an answer on May 23, 2026 at 8:04 am

    You want to use mpl::inherit_linearly

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

Sidebar

Related Questions

I have a class, with public API. I have other classes who inherit from
I'm using an API that has a Member class. I wish to extend this
I wish to do this using only XAML - How to add an additional
I wish HTML could do something semantically equivalent to this; <dl class=main-list> <definitionitem> <dt>Some
I wish I could figure this out. I need to produce a table with
I wish to iterate over a set but the contents of the set will
I wish to capture data from http://www.kitco.com/texten/texten.html : <html> <head> <title>Text Only Market Page</title>
Wish anybody can help me with this error Column 'Sales.No_' is invalid in the
I wish to set the datasource as my bound field item, but i failed
I wish I could write LINQ to Entity queries that called other functions: from

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.