Am I declaring a partially specialized friends class? - very embarrassed

For too long I twisted my thumbs over it. I am trying to implement one linked list using two different allocators for both nodes and the type that they point to. The following code continues to complain about me that I partially specialize the declaration of the friends class in the definition of SingleListNode:

namespace containers { template<typename T, typename TAlloc, typename NAlloc>class SingleList; // forward declaration template<typename T, typename TAlloc = std::allocator<T>> class SingleListNode { template<typename T1, typename T2, typename T3> friend class SingleList<T1, T2, T3> ; // partially specialized??? // class definition }; template<typename T, typename TAlloc = std::allocator<T>, typename NAlloc = std::allocator<SingleListNode<T>>> class SingleList { // class definition }; } // end of namespace containers 

He continues to tell me:

../src/singlelist.h: 21:16: error: specialization "template template containers" :: SingleList should appear in the namespace area .. /src/singlelist.h:21:39: error: partial specialization 'container: : SingleList declared 'friend

As far as I can tell, this is not a specialization. Perhaps this is a bug in the GCC compiler? Otherwise, where am I mistaken?

+5
source share
1 answer

You are declaring a template friend class, so the correct syntax is

  template<typename T1, typename T2, typename T3> friend class SingleList; 

without <T1, T2, T3> after SingleList . See, for example, β€œpractical use case” here

+7
source

Source: https://habr.com/ru/post/1385149/


All Articles