我是否声明了部分专门化的友类?-非常困惑
Am I declaring partially specialized friend class? - very confused
我已经在这个问题上花了太多时间了。我正在尝试使用两个不同的分配器为节点和它们指向的类型实现单个链表。下面的代码一直抱怨我在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
一直在告诉我:
./src/SingleList .h:21:16:错误:' template struct containers::SingleList '的特化必须出现在命名空间作用域中/src/singllist .h:21:39:错误:partial特殊化' containers:: singllist '声明为' friend '
据我所知,这不是专门化。也许这是GCC编译器中的一个bug ?否则,我哪里出错了?
您正在声明一个模板化的友类,因此正确的语法是
template<typename T1, typename T2, typename T3>
friend class SingleList;
, SingleList
后面没有<T1, T2, T3>
。例如,这里的"实际使用示例"
相关文章:
- .cpp和.h文件中的模板专用化声明
- 未在作用域中声明unordered_map
- C++避免重复声明的语法是什么
- 如何确保C++函数在定义之前声明(如override关键字)
- 错误:未在此范围内声明'reverse'
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 为什么在定义函数之前先声明它
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- #ifdef和未声明的标识符
- 没有显式声明的int[]中的foreach
- 在基于范围的for循环中使用结构化绑定声明
- 在将变量声明为引用时,堆在释放后使用
- C++:无法访问声明的受保护成员
- 为什么我不能在一个类的不同行中声明和定义成员变量?
- Intel C 编译器的编译非常慢,无法编译递归声明返回
- 在堆上声明和初始化非常大的数组
- 声明一个非常大的整数向量
- 我可以在类中声明一个非常大的数组吗,C++
- 非常不平凡的模板朋友声明
- 我是否声明了部分专门化的友类?-非常困惑