Q:

Inheriting from protected classes in C+++

Suppose I have the following declaration:
class Over1
{
   protected:
      class Under1
      {
      };
};

I know that I could do the following:
class Over2 : public Over1
{
   protected:
        class Under2 : public Under1
        {
        };
};

But is there a way to declare Under2 without Over2? 
Since you would have to extend Over1 to use any derivative of Under1 this may seem silly, but in this situation there might be 30 different flavors of Under. I can either:

Put them all inside Over1 : Not
attractive since Over2 may only use
1 or 2 of them 
Put them each in
their own version of Over : Not
attractive since then you will have
to multiply inherit from almost the
same class. 
Find a way to create
children of Under1 without creating
children of Over1

So is this possible?
Thanks.

A:

Using templates and explicit specializations you can do this with just one additional class declaration in Over1.
class Over1
{
protected:
  class Under1
  {
  };

  template <typename T>
  class UnderImplementor;
};

struct Under2Tag;
struct Under3Tag;
struct Under4Tag;

template <>
class Over1::UnderImplementor<Under2Tag> : public Over1::Under1
{
};

template <>
class Over1::UnderImplementor<Under3Tag> : public Over1::Under1
{
};

template <>
class Over1::UnderImplementor<Under4Tag> : public Over1::Under1
{
};

Hope this helps.

