error: expected unqualified-id before "char"

Ok, so I have seen this error all over this forum and other forums and have tried and double checked all my code but I still get this error.

I have commented out the entire main() function with no difference to the compiler error, so I would assume that it is not the cause. Also, the main() function does not throw any compilation errors.

There are 3 files below: main.cpp, hash.h, and hash.cpp.



g++ -Wall -c main.cpp
main.cpp:9:1: error: unterminated comment
In file included from main.cpp:6:
hash.h:9: error: expected unqualified-id before char
hash.h:9: error: expected ) before char
make: *** [main.o] Error 1



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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

// main.cpp

#include <iostream>
#include <fstream>
#include <string>
#include "hash.h"

using namespace std;
/*
int main()
{
	ifstream inFile;
	inFile.open("hw6q5in.txt");
	int i;
	inFile >> i;
	string input [i];
.
.
.
.
.
. 

*/

// hash.h

#ifndef hash	
#define hash
#include <iostream>
#include <string>

using namespace std;

int hash(char *v, int M);

#endif




// hash.cpp

#include <iostream>
#include <string>
#include <sstream>
#include <iterator>

using namespace std;

int hash(char *v, int M)
{
int h = 0;
int a = 127;
for (; *v != 0; v++)
{
	h = (a*h + *v) % M ;
}
return h ;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
#ifndef hash	
#define hash
#include <iostream>
#include <string>

using namespace std;

int hash/*<--- This is a macro that resolves to nothing*/(char *v, int M);

#endif 


No comment.
Topic archived. No new replies allowed.