template

This is a discussion on template within the C++ Programming forums, part of the General Programming Boards category; Here is the linked list class which is of type String: Code: template <class T> class List { public: List(); ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    94

    Post template

    Here is the linked list class which is of type String:
    Code:
    template <class T>
    class List
    {
      public:
          List();
          ~List();
          void clear ();
          void makeLink (const T &nData);
    	
          T nodeData;
          List *next, *head, *tail;
    };
    Code:
    struct String
    {
       char str[MAX];
       int result;
       int hashKey;
    
       friend ostream& operator <<(ostream& out, String& wrd);
    	
       void operator= (List *head);
       int operator== (const String& wrd) const;
       int operator < (const String& wrd) const;
       int operator > (const String& wrd) const;
    };
    
    //------------------------------------------------------------------------------
    void String::operator= (List *head)
    {
    	head=NULL;
    }
    Here I am trying to create an array of linked lists in the hash t
    Code:
    //---------------------------CONSTRUCTOR---------------------------------
    template <class T>
    HashTable<T>::HashTable ()
    {
        size=0;
        for (long i=0; i< MAX_SIZE; i++)
             htable[i]= new List<T>;    <----array of linked list created ??
    }
    The error message I am receiving is :

    'List' : use of class template requires template argument list
    see declaration of 'List'

    I am not to sure how I can overcome this problem
    simple is always an understatement.....

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    What type is htable? Perhaps it is the wrong type and that is confusing the compiler?
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    94
    I am still in the process of creating the hash table. It implements the division method and collisions are resolved using chaining.

    I am really stuck big time an would appreciate some help.
    simple is always an understatement.....

  4. #4
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    I mean.. what is the datatype, IE, List**, or what .
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    94
    Uhhhh If I understood you correctly the type of the hash table is : HashTable<String>.
    simple is always an understatement.....

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    94
    Anyone....pls help
    simple is always an understatement.....

  7. #7
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    void operator= (List *head);

    This is what your compiler is talking about. List<???>.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    94
    Ok...I must be an absolute moron because I still dont get it My linked list is declared as List<String>.

    If Im overloading the operator= incorrectly, can someone pls correct it for me because I need an overloaded operator= to be able to do : htable[i]= new List<T>
    simple is always an understatement.....

  9. #9
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    void operator= (List *head);

    You are missing your template parameter here. List alone is no datatype. You need to specify a datatype for it.

    List<int> l;

    would be correct, while

    List l;

    will get you the errormessage you got.


    Edit:
    List *next, *head, *tail;
    This line as well. You need a datatype.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  10. #10
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    If Im overloading the operator= incorrectly, can someone pls correct it for me because I need an overloaded operator= to be able to do : htable[i]= new List<T>
    You maybe got the concept wrong, I don't see why you would do this. What datatype is htable ?
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  11. #11
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    "Edit:
    List *next, *head, *tail;
    This line as well. You need a datatype."

    You don't need to specify a full type inside the class declaration, it's assumed to be whatever the template parameters are.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Specialising a member function with a template template parameter
    By the4thamigo_uk in forum C++ Programming
    Replies: 10
    Last Post: 10-12-2007, 04:37 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  5. oh me oh my hash maps up the wazoo
    By DarkDays in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2001, 11:54 AM

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