Errors in a simple hash table class.

This is a discussion on Errors in a simple hash table class. within the C++ Programming forums, part of the General Programming Boards category; I decided to test-compile a class that I'm making and I'm getting strange errors which i've never seen before in ...

  1. #1
    Not just a squid...
    Join Date
    Sep 2004
    Posts
    25

    Errors in a simple hash table class.

    I decided to test-compile a class that I'm making and I'm getting strange errors which i've never seen before in some very simple code. I'm posting the three files here with errors numbered and their occurences commented. My compiler is Dev-C++ 4.9.9.1. If anyone has any ideas please let me know.

    ERRORS:
    1 expected unqualified-id before "using"
    2 expected `,' or `;' before "using"
    3 `cout' undeclared (first use this function)
    4 `endl' undeclared (first use this function)
    5 ISO C++ forbids declaration of `vector' with no type
    6 expected `;' before '<' token

    Code:
    MAIN:
    
    #include <cstdlib>
    #include <iostream>
    #include "HashTable.h"
    
    using namespace std;   // <- Error 1 and 2
    
    int main()
    {
        HashTable H;
    
        cout << "End of Program." << endl;  // <- Error 3 and 4
    
        return EXIT_SUCCESS;
    }
    
    HASHTABLE.H:
    
    #ifndef _HashTable_H_
    #define _HashTable_H_
    
    class HashTable
    {
        public:
            HashTable(int size = 101);
                    
        private:
            vector<char*> array;    // <- Error 5 and 6
    }
    
    #endif
    
    
    HASHTABLE.CPP:
    
    #include <iostream>
    #include <vector>
    #include "HashTable.h"
    
    using namespace std;
    
    HashTable::HashTable(int size)
    {
        array.resize(size);
    }

  2. #2
    fuh
    fuh is offline
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    Put using namespace std in hashtable.h
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    95
    vector<char*> array; // <- Error 5 and 6
    }

    End your class with a ";"

    You also need to include <vector> in HashTable.h, and either use a using directive or write std::vector every time you use vector.

    I think you also need to include <ostream> in your main source file for endl.

  4. #4
    Not just a squid...
    Join Date
    Sep 2004
    Posts
    25
    I can't believe I forgot the ';' at the end. Just goes to show what fresh eyes can do. One more minor thing: when I add "using namespace std;" and <vector> to the h file should they be outside or inside the #define directive? Does it matter either way?

  5. #5
    Registered User
    Join Date
    Dec 2004
    Posts
    95
    Put them inside the #define.
    I wouldn't necessarily use "using namespace std" (pulling in the entire std:: namespace) when "using std::vector" would suffice (as here).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  2. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  3. question about .net to 6.0 change causing errors
    By jverkoey in forum C++ Programming
    Replies: 17
    Last Post: 03-23-2004, 09:45 AM
  4. progarm doesnt compile
    By kashifk in forum Linux Programming
    Replies: 2
    Last Post: 10-25-2003, 05:54 PM
  5. extra word printing
    By kashifk in forum C++ Programming
    Replies: 2
    Last Post: 10-25-2003, 04:03 PM

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