compiling error

hi all
i spent a whole day to find out what the f**k is wrong with this code....
still got this error....plz anyone help!!!!
1
2
3
4
C:\>g++ huffman_driver.cpp -o huffman
In file included from huffman_driver.cpp:3:0:
huffman.h:33:31: error: expected identifier before numeric constant
huffman.h:33:31: error: expected ',' or '...' before numeric constant


this is my 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
32
33
34
35
36
37
38
39
40
huffman.h

#include <iostream>   //for cout and cin
#include <string>    //using string variable
#include <fstream>   //working with input and output file
#include <vector>

using namespace std;

 struct huff_node
{
	unsigned long int count;	//cout the probibility of each character
	signed short int ch;		//store the character
	struct  huff_node * left;	// these are 3 pointers to structure for making huffman tree
	struct  huff_node * right;
	struct  huff_node * parent;
	bool ignore;			//true-> if we already handled this node
};

class huffman
{

public:

huffman (char const *);		// cunstructor of the class...get file name as input
void getLastError(void);	// print out errorMessage
private:

bool error_occured;   //true -> means some error ocurred !!!
string errorMessage;  //store error message
const char * inputFileName;      //store input file name
const char * outputFileName;	//store output file name
ofstream myFileOut;   		//handle to input file
ifstream myFileIn;		//handle to output file
vector<struct huff_node> vec (255);     //array of our huffman structure
void readInputFile(void);   //read each char from input file and count probility and store in array


};


and...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
huffman_driver.cpp

#include <iostream> 
  
#include <string>      

#include "huffman.h"


using namespace std;


int main()
{

const char * a="571.txt";

huffman in1("571.txt");



return 0;
}

and...
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
huffman.cpp

#include <iostream>   //for cout and cin

#include <string>    //using string variable

#include "bitio.h"     //input output bitoperation using this class in current directory

#include <fstream>   //working with input and output file

#include <vector>

#include "huffman.h"

using namespace std;



huffman::huffman(char const * inputFileName)
{
	
errorMessage="No Error Yet!!!";
	
error_occured=false;
	
this->inputFileName=inputFileName;
	
for (int i=0;i<255;i++)
	{
		
vec[i].count=0;
		
vec[i].ignore=false;
		
	
}
}


void huffman::readInputFile(void)
{

	//inputFileName="571.txt";
	
myFileIn.open(inputFileName,ios::in|ios::binary);
	
if (!myFileIn.is_open())
	{
	
		errorMessage="can not open input file " + (string) inputFileName + " .check if file exist!!!";
		
getLastError();
		
error_occured=true;
		
exit(1);
	}	
	
	
unsigned char * byte;
	
byte=new unsigned char [1];
	
while (! myFileIn.eof())
	{
		
myFileIn.read((char *)byte,1);
		
vec[*byte].count++;
		
vec[*byte].ch=(unsigned char)(*byte);
	}
	
for (int i=0;i<255;i++)
	{	
		
if (vec[i].count==0)
		{
			
vec[i].ignore=true;
		}
	}
	
cout<<endl<<"now our vector size is : "<<(int)vec.size()<<endl;
	myFileIn.close();

	
}	



void huffman::getLastError(void)
{
	
	cout<<endl<<errorMessage<<endl;
}


thx in advance...
First two things I see; no header guards on huffman.h (and you do include it twice) and you've got using namespace std in your header file, which is a bad idea and often leads to problems.

You're using exit without including the cstdlib. Your compiler shouldn't really let you get away with that.


Anyway, what's crippling your progress is this line.

vector<struct huff_node> vec (255); //array of our huffman structure

Lose the struct, and note that we declare an array using the square brackets, like this: vec[255]

However, making it an array of vectors makes little sense. Why not just try this:

vector<huff_node> vec;

If you didn't mean array, and you actually wanted a vector of size 255; this is the definition of a class. The vector is not being constructed here, so this is not the place to be calling constructors.

I suspect you didn't mean array, as later you try this:
vec[i].count=0;
which suggests that you think vec should be a vector, not an array of vectors.

It compiles when I change

vector<struct huff_node> vec (255); //array of our huffman structure

to
vector<huff_node> vec; //vector of our huffman structures

If I wanted to fiddle with the size of vec, I would do it in the class constructor (and i'd have to, if I didn't want a segfault, but those are easy to fix :) ).




Last edited on
thx so much Moschops for quick reply...thats y this is the best c/c++ forum ever!!!

it compiles and works well as you said...thx again.
Topic archived. No new replies allowed.