template list syntax error

This is a discussion on template list syntax error within the C++ Programming forums, part of the General Programming Boards category; Ok, I'm working on a game and I'm having problems with constructors when allocating arrays of object, so I decided ...

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    template list syntax error

    Ok, I'm working on a game and I'm having problems with constructors when allocating arrays of object, so I decided I'd make a generic linked list structure to get around it. So far I've got the specification written:
    Code:
    #ifndef MYLIST2_H
    #define MYLIST2_H
    
    template <class T>
    class mylist;
    
    template <class T>
    class node {
    private:
        node(T,node*);
        node* next;
        T data;
        friend class mylist<T>;
    };
    
    template <class T>
    class mylist {
    private:
        node *head, *cursor;
    public:
        mylist();
        ~mylist();
        void addtoend(T);
        void addtostart(T);
        void remove();
        void addbefore();
        void clear();
    };
    
    #endif
    This looks good to me, but when I compile it I get a 'syntax error before '*'' on this line:
    Code:
    node *head, *cursor*;
    What am I doing wrong?
    Illusion and reality become impartiality and confidence.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    node is a template class, you need to specify its type:
    Code:
    node<T> *head, *cursor;
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21