Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ STL
#include "Node.h"
template<class Type>                           //Error  4   error C3857: 'List': multiple template parameter lists are not allowed

class List
{
 
public:
    List();
    ~List();
    void AddNode(void);
 

private:
    Node<Type>* m_pNode;
 
};                                            //Error   3   error C2989: 'List' : class template has already been declared as a non-class template

 
template<class Type>
List<Type>::List():m_pNode(NULL)       //Error   5   error C2988: unrecognizable template declaration/definition       //Error   6   error C2059: syntax error : '<'

 
{
}
 

 
template<class Type>
List<Type>::~List()                    //Error  7   error C2588: '::~List' : illegal global destructor    //Error   8   fatal error C1903: unable to recover from previous error(s); stopping compilation

{
    Node<Type>* pNode = NULL;
 
    while (m_pNode != NULL)
    {
        pNode = m_pNode;
        m_pNode = m_pNode->m_pNext;
        delete pNode;
    }
    m_pNode = NULL;
}
 
template<class Type>
void List<Type>::AddNode( void )
{
    if (m_pNode == NULL)
    {
        m_pNode = new Node<Type>();
    }
    else
    {
        Node* pTailNode = m_pNode;
 
        while (pTailNode->m_pNext != NULL)
        {
            pTailNode = pTailNode->m_pNext;
        }
 
        pTailNode->m_pNext            = new Node<Type>();
        pTailNode->m_pNext->m_pBefore = pTailNode;
 
    }
}
 
template<class Type>
class Node
{
    friend class List<Type>; // Error   1   error C2059: syntax error : '<'

public:
    Node ();               //Error  2   error C2238: unexpected token(s) preceding ';'

private:
    Type  m_nData;
    Node<Type>* m_pNext;
    Node<Type>* m_pBefore;
};
 
template<class Type>
Node<Type>::Node() : m_pNext(NULL),m_pBefore(NULL)
{
}
 
#include "List.h"

int _tmain(int argc, _TCHAR* argv[])
{
    List<int> myList;
    myList.AddNode();
 
    return 0;
}
 

Thanks for your help!!!
Posted 6-Jun-10 0:37am
jc24386
Edited 6-Jun-10 6:02am
Moak11.4K
v2
Comments
Moak at 6-Jun-10 11:04am
   
Updated subject, tags and formatting. I am pretty sure I have seen this question previously today, wonder where it went?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try forward declaring List in Node.h:
 
template <class Type> class List;
 
and then declare it as a friend in Node<Type>:
 
friend List<Type>;
 
Cheers,
 
Ash
  Permalink  
Comments
jc24 at 6-Jun-10 7:32am
   
Thank you very much
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

You may want to take a look at Sam Buss' excellent linked list. I use it in my CXMLProfile class here on CP. You can download it from Sam's site at http://www.math.ucsd.edu/~sbuss/MathCG/[^].
 
Click on the link for "Ray Trace software". In the zip file you will find a directory called DataStructs. You want the CLinkedList file.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 OriginalGriff 120
3 PIEBALDconsult 110
4 Zoltán Zörgő 99
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 6 Jun 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100