Ian Haggerty
Ian Haggerty

Reputation: 1751

Am I declaring partially specialized friend class? - very confused

I've been twiddling my thumbs over this one for far too much time now. I am trying to implement a single linked list using two different allocators for both the nodes and the type to which they point. The following code keeps complaining at me that I am partially specializing the friend class declaration within the SingleListNode definition:

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

Keeps telling me:

../src/singlelist.h:21:16: error: specialization of ‘template struct containers::SingleList’ must appear at namespace scope ../src/singlelist.h:21:39: error: partial specialization ‘containers::SingleList’ declared ‘friend’

So far as I can tell, this isn't a specialization. Perhaps it is a bug in the GCC compiler? Otherwise, where am I going wrong?

Upvotes: 8

Views: 4656

Answers (1)

bbtrb
bbtrb

Reputation: 4085

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

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

without the <T1, T2, T3> after SingleList. See, for instance, the "practical usage example" here

Upvotes: 13

Related Questions