I keep getting these errors. I'm so lost please help... fairly new to c++ programming.

hashheader.h(8) : error C2144: syntax error : 'int' should be preceded by ';'

hashheader.h(8) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

hashheader.h(14) : error C2061: syntax error : identifier 'string'

hashheader.h(20) : error C2061: syntax error : identifier 'HashElement'

hashheader.h(26) : error C2146: syntax error : missing ';' before identifier 'get'

hashheader.h(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

hashheader.h(26) : error C2061: syntax error : identifier 'string'

hashheader.h(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

hashheader.h(26) : warning C4183: 'get': missing return type; assumed to be a member function returning 'int'

hashheader.h(36) : error C2146: syntax error : missing ';' before identifier 'words'

hashheader.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

hashheader.h(36) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

#include <iostream>
#include <cstring>
#include <fstream>
#ifndef HASHTABLE
#define HASHTABLE


tyepdef int HashElement;

class HashTable
{
public:

	int hash(string word);
	/* 
	a function that determines an array index for key.
	the function sums the values of the ascii codes for each letter
	in the key and returns the sum to the caller.
	*/
	void put(HashElement entry);
	/*
	places the entry into a hash table
	it uses linear probing to resolve collisions.
	*/
	
	HashElement get(string key);
	/*returns the element in the hash table that has the key 'string key'. 
	the record is retrieved by hashing.
    */
	
	void display (int lowerbound, int upperbound);
	//prints entries between lower bound and upper bound

private:

	string words[16000];
	//array of 16000 strings

};

#endif

add using std::string after the include files

Move the code gards (lines 4 and 5) up before the include files.

Edited 7 Years Ago by Ancient Dragon: n/a

now I get these errors.....


hashheader.h(10) : error C2144: syntax error : 'int' should be preceded by ';'

hashheader.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

hashheader.h(22) : error C2061: syntax error : identifier 'HashElement'

hashheader.h(28) : error C2146: syntax error : missing ';' before identifier 'get'

hashheader.h(28) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

hashheader.h(28) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

hashheader.h(28) : warning C4183: 'get': missing return type; assumed to be a member function returning 'int'

Hi,

I see you typo it should rather read

typedef int HashElement

You misspelled typedef. Also as Ancient Dragon says include using std::string;

A piece of advice, in all your c++ programs always put without fail using namespace std; to read something like

#include <abcde>
#include <efghij>

using namespace std;

That should work

This article has been dead for over six months. Start a new discussion instead.