Does not name a type error using G++

The code that follows is from a textbook. I am using g++ 4.5.0 via MinGW environment on Windows 7 Professional x64. This code should work as it's from a textbook, but I get an error. The code is a template class definition for a hash-table. The table (data) is an array where each position is a vector that will contain records.

Here is the code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//file:hashtable.h
#ifndef RAILE12_HASHTABLE_H
#define RAILE12_HASHTABLE_H
#include <cstdlib>        // Provides size_t
#include <vector>        // Provides the STL vector class

namespace raile12_hashtable
{
    typedef std::size_t size_type;
    template <class RecordType, size_type TABLE_SIZE, int hashkey(const RecordType&)>
    class hashtable
    {
    public:
        // Constructors
        hashtable();
        // Modification member functions
        void insert(const RecordType& entry);
        void remove(int key);
        // Constant member functions
        void find(int key, bool& found, RecordType& result) const;
        bool is_present(int key) const;
        size_type size( ) const { return total_records; }
    private:
        vector<RecordType> data[TABLE_SIZE];
        size_type total_records;
        // Helper member function
        size_type hash(int key) const;
    };
}

#endif 


The error is:
hasht.h:23:9: error: 'vector' does not name a type

which is the line bolded in the code.

After doing some searching the best answer I have gotten is there is a problem with instantiating the variable, but I don't know how to fix the problem. I tried scoping the line using the namespace and the class name but that causes more errors (although I could have made a mistake doing that).

If anyone can help me I'd greatly appreciate it.
-taco
Last edited on
std::vector<RecordType> data[TABLE_SIZE];

you need to prefix with the namespace
Wow. Just, wow. Thank you very much jsmith. I never tried "std::" because I was using a different namespace.

[EDIT] - Haha, I am defining the namespace raile12_hashtable not using it. So it makes even more sense to use "std::" now.
Last edited on
Topic archived. No new replies allowed.