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?
Template friendsBoth function template and class template declarations may appear with the friend specifier in any non-local class or class template (although only function templates may be defined within the class or class template that is granting friendship).
" typename " is a keyword in the C++ programming language used when writing templates. It is used for specifying that a dependent name in a template definition or declaration is a type.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With