0

I have a class similar to this:

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 >
        {
                    ....

The problem is I get an error in template argument for LockFreeMemMng('Node' : undeclared identifier...).

How can I use forward declaration of Node and Link in above of MemMngList implementaion?

template< typename T, typename Allocator >
class MemMngList;

//Forward Declaration of Node and Link
StarPilot
  • 2,246
  • 1
  • 16
  • 18
MRB
  • 3,752
  • 4
  • 30
  • 44
  • possible duplicate of [Forward declaration of nested types/classes in C++](http://stackoverflow.com/questions/951234/forward-declaration-of-nested-types-classes-in-c) – TobiMcNamobi Nov 04 '14 at 10:02

1 Answers1

2

You can't forward declare something inside a class declaration. You need to move it somewhere outside the class and use friend if you want to access private members:

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;

    ...
};
Raxvan
  • 6,257
  • 2
  • 25
  • 46