0

我有一个类似的课程:

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' : undeclared identifier...) 的模板参数中遇到错误。

如何使用MemMngList 实现的前向声明Node和上面的声明?Link

template< typename T, typename Allocator >
class MemMngList;

//Forward Declaration of Node and Link
4

1 回答 1

2

您不能在类声明中转发声明某些内容。如果你想访问私人成员,你需要将它移到课堂外的某个地方并使用朋友:

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;

    ...
};
于 2013-11-12T17:28:13.430 回答