嵌套模板类的前向声明
Forward declaration of nested template classes
我有一个类似的类:
template< typename T, typename Allocator >
class MemMngList : protected LockFreeMemMng<Node, Link>
{
public:
typedef T Type;
typedef Allocator AllocatorType;
struct Node : public LockFreeNode
{
public:
struct Link : protected LockFreeLink< Node >
{
....
问题是我在 LockFreeMemMng('Node' : 未声明的标识符...)的模板参数中出现错误。
如何在上述 MemMngList 实现中使用 Node
和Link
的前向声明?
template< typename T, typename Allocator >
class MemMngList;
//Forward Declaration of Node and Link
不能在类声明中转发声明某些内容。如果您想访问私有成员,您需要将其移动到类外的某个位置并使用 friend:
template <typename T, typename Allocator>
struct NodeType : public LockFreeNode< NodeType<T,Allocator> >
{
...
template <typename,typename>
friend class MemMngList;
};
template <typename T, typename Allocator>
struct LinkType : public LockFreeLink< NodeType <T,Allocator> >
{
...
template <typename,typename>
friend class MemMngList;
};
template< typename T, typename Allocator >
class MemMngList : protected LockFreeMemMng< NodeType <T,Allocator> , LinkType <T,Allocator> >
{
typedef NodeType <T,Allocator> Node;
typedef LinkType <T,Allocator> Link;
...
};
相关文章:
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- 如何在嵌套类中正确使用友元声明?
- 具有嵌套类声明的类模板 (C++)
- 如何在该接收类之外声明嵌套类的方法
- MSVC 2017 - 错误 - 如何将模板类 X 的模板成员函数声明为嵌套类 X::Y 的好友
- 以嵌套类为参数的友元模板声明
- 我们可以在main函数中声明嵌套类对象吗
- C++中嵌套模板声明的限制
- 类外的前向声明有效,但在嵌套时无效
- 声明嵌套在模板参数中的类型的变量?
- 这个嵌套结构声明是什么意思?
- 声明嵌套基模板类实例是派生类的好友
- C++17 是否允许向前声明嵌套类
- 有没有办法在C++中预先声明嵌套类
- 声明嵌套结构的指针
- 如何正确声明嵌套类
- 如何在层次结构头文件中声明嵌套类型
- 带嵌套类的链表:如何在声明嵌套类类型之前使用它
- 无法在 main 中声明嵌套类的即时。"对 Class::NestedClass::NestedClass() 的未定义引用;
- 前向声明嵌套在模板类中的模板类