Thread: Syntax problems with Class Template

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    7

    Syntax problems with Class Template

    I can't seem to resolve a syntax error, that is only occuring when I use a template with a pointer. Its just a basic linked list, here is the first part of my header file:

    Code:
     #ifndef LISTTEMP_H
    #define LISTTEMP_H
    #include <iostream>
    
    template <class type>
        class listtemp{
    	public:
    		const listtemp <type>& operator= (const listtemp<type>&);
    		void initializelist();
    		bool islistempty();
    		bool islistfull();
    		void print();
    		int length();
    		void destroylist ();
    		void retrievefirst(type& firstelement);
            
    		
    		listtemp();
    		
    		listtemp(const listtemp <type>& otherlist);
    		
    		~listtemp();
    		
    	protected:
    	    nodetype<type> *first;                        //line 25
    	    nodetype<type> *last;
    		
    		
    };
    
        template <class type>
        bool listtemp<type>::islistempty(){
            return (first == null);
        }
        
        template <class type>
        bool listtemp<type>::islistfull(){
            return false;
        }
    
    template <class type>
        listtemp<type>::listtemp(){
            first = NULL;
            last = NULL;
        }
        
        template <class type> 
        void listtemp<type>::destroylist(){
            nodetype<type> *temp;                          //line 49
        }
    and the error message I am getting is as follows:


    Compiler: Default compiler
    Building Makefile: "E:\C++Programs\Makefile.win"
    Finding dependencies for file: E:\C++Programs\Sortedlistmain.cpp
    Executing make...
    make.exe -f "E:\C++Programs\Makefile.win" all
    g++.exe -D__DEBUG__ -c Sortedlistmain.cpp -o Sortedlistmain.o -I"E:/Dev-Cpp/include/c++/3.3.1" -I"E:/Dev-Cpp/include/c++/3.3.1/mingw32" -I"E:/Dev-Cpp/include/c++/3.3.1/backward" -I"E:/Dev-Cpp/lib/gcc-lib/mingw32/3.3.1/include" -I"E:/Dev-Cpp/include" -g3 -O0 -O3 -g3

    In file included from sortlist.h:3,
    from Sortedlistmain.cpp:3:
    listtemp.h:25: error: syntax error before `*' token
    listtemp.h:26: error: syntax error before `*' token
    listtemp.h: In member function `void listtemp<type>::destroylist()':
    listtemp.h:49: error: syntax error before `>' token



    I have checked multiple references allready, and my code syntax looks the same, so I'm guessing it may be compiler related, however I am not sure. Any help is greatly appreciated.
    Last edited by cuddlez.ini; 12-05-2004 at 07:11 PM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >so I'm guessing it may be compiler related
    Well, I'll buy into the compiler bug if you can show me where nodetype is declared.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    7

    Doh!

    Well, that got rid of a lot of problems, thank you, guess I need to spend more time reading my book, and not trying to jump ahead.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >guess I need to spend more time reading my book, and not trying to jump ahead.
    Books are for weenies. You learn more by trial and error...and error, and error, and error.
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Crazy errors caused by class, never seen before..
    By Shamino in forum C++ Programming
    Replies: 2
    Last Post: 06-10-2007, 11:54 AM
  2. Weird errors.
    By Desolation in forum C++ Programming
    Replies: 20
    Last Post: 05-09-2007, 01:10 PM
  3. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  4. Declare a template class as a friend?
    By AH_Tze in forum C++ Programming
    Replies: 11
    Last Post: 05-19-2004, 09:24 PM