1

Assume the following class:

struct X : A, B, C{};

What problems might appear if I change it to the following?

struct indirect_C : C{};
struct indirect_BC : B, indirect_C{};
struct X : A, indirect_BC{};

The example may seem contrived, but it happens when you to inherit a variable number of bases through variadic templates, and also want functionality from those bases made available (or not) in the derived class.

template<class... List>
struct X : List...{
  using List::something...; // ill-formed in C++11
};

As such, you need a work-around, which is inheriting "recursively" and bringing the functionality into scope at every recursive step:

template<class Head, class... Tail>
struct inherit_indirect
  : Head
  , inherit_indirect<Tail...>
{
  using Head::something;
  using inherit_indirect<Tail...>::something;
};

template<class T>
struct inherit_indirect<T>
  : T
{
  using T::something;
};

(See for example this answer of mine, where I used this technique.)

Community
  • 1
  • 1
Xeo
  • 129,499
  • 52
  • 291
  • 397
  • can you please describe the usecase? the committee would welcome a list of usecases that a "using T::x..." would have. – Johannes Schaub - litb Nov 11 '12 at 17:41
  • @Johannes: I know there is a movement to expand unpacking mechanics, and things like `using T::T...;` or `using T::x...;` might be possible in a later standard. This particular question came up again [in this thread](http://isocpp.org/forums/iso-c-standard-discussion?place=msg%2Fstd-discussion%2Fnd0OFYBxvP0%2FlKLCp7TQgbYJ) and would also be fixed by lifting some restrictions on unpacking. I don't have any specific usecase in mind that wouldn't be fixed by that, and I was just interested if any problems might appear. – Xeo Nov 11 '12 at 17:46

1 Answers1

2

You cannot directly initialize class base objects B and C anymore in the constructor of X.

Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
  • Oh, a very good point. So I'd need to forward arguments through `indirect_BC`, possibly with a list of tuples.. ugh. – Xeo Nov 11 '12 at 18:42