0

I would like to implement the CRTP on a parameterized Base, and make Base a friend of Derived:

template <template <typename> class Derived, class T>
class Base;

template <class T>
class Derived : public Base<Derived, T>
{
  friend class Base<Derived, T>;
};

I have a compilation error on VS2012 with the following message:

error C3200: 'Derived<T>' : invalid template argument for template parameter 'Derived', expected a class template

Thanks for your help.

Thomas Hugel
  • 146
  • 1
  • 5
  • [Works for me](http://ideone.com/OzlGcc). Looks like MSVS has a problem with templates. It seems to consider `Derived` to be only the injected-class-name, and not the name of the template. – Kerrek SB Nov 14 '14 at 10:55

1 Answers1

2

Try this:

friend class Base<::Derived, T>;

If that doesn't work, your compiler doesn't support this form of friend declaration (it should, but what do I know), and you'll have to work around by extending the friendship to all Base instantiations.

template <template <typename> class D, class BT>
friend class Base;
Sebastian Redl
  • 69,373
  • 8
  • 123
  • 157
  • Thank you, but your solution with global scope now gives the following error: `error C2972: 'Base' : template parameter 'Derived' : the type of non-type argument is invalid` – Thomas Hugel Nov 14 '14 at 13:40