繁体   English   中英

嵌套模板类的前向声明

[英]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实现的上面使用NodeLink前向声明?

template< typename T, typename Allocator >
class MemMngList;

//Forward Declaration of Node and Link

你不能在类声明中转发声明的东西。 如果要访问私有成员,您需要将其移到课堂外的某个地方并使用朋友:

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;

    ...
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM