Search code examples
c++templatesfriend

Friend with own class template with other template parameter


Is it possible to declare your own class template with other template parameters as a friend?

template<class T, class... Ts>
class A {
    template<class U> friend class A<U, Ts...>;    //compile error - C3772  'A<U>': invalid friend template declaration 
};

Solution

  • template<class T, class... Ts>
    class A {
        template<class U, class... Us> friend class A; //here you go
    };
    

    There is no need to specify template arguments after A