I have switched to c++ from c. I have already done this kind of thing in c (Please don't dig the rest of the code for now just see the way of calling to functionfind_two_smallest();
it's definition in c and then below in c++ it's call. definition and declaration) because the problem is just there, No where else:I have written the full code because i am mentioning the line numbers which are giving errors.
void huffman()
{
struct node *temp, *pmin1, *pmin2, *pt = tree;
while(remaining>2)
{
find_two_smallest(&pmin1, &pmin2);//please pay attention on this function
}
The definition of this function call in c is : void Huffman::find_two_smallest(struct Node **pmin1, struct Node **pmin2) { struct node *ppt, *pt = tree; struct node *min1 = tree; struct node *min2 = NULL; ppt = NULL; while(pt!=NULL) { if(pt->is_processed == 0) { if(pt->freq < min1->freq) { min2=min1; min1 = ppt; } } ppt = pt; pt = pt->next; } *pmin1 = min1; *pmin2 = min2; }
This was all in c and it works absolutely fine. Actually i am trying to find two minimum number. whereas my structure is:
struct node
{
unsigned int symbol;
int freq;
struct node *left, *right,*next;
int id;
int is_processed;
};
struct node *tree;
I do the same in c++.Except that i ahave used "Node" instead of "node"There i also need to declare this find_two_smallest()function in class Huffman. That i do like this:
void find_two_smallest(struct Node **pmin1, struct Node **pmin2);
whereas definition i am doing this: I have written the line numbers to predict errors:*
31 void find_two_smallest(struct Node **pmin1, struct Node **pmin2)
32 {
33 struct Node *ppt, *pt = tree;
34 struct Node *min1 = tree;
35 struct Node *min2 = NULL;
36 ppt = NULL;
37 while(pt!=NULL)
38 {
39 if(pt->is_processed == 0)
40 {
41 if(pt->freq < min1->freq)
42 {
43 min2=min1;
44 min1 = ppt;
45 }
46 }
47 ppt = pt;
48 pt = pt->next;
49 }
50 *pmin1 = min1;
51 *pmin2 = min2;
52 }
Whereas function call i do the same way as i do in c. The result is largenumber of errors. I am beginner to c++ just switched from c. Any help please ? You can see the line numbers i have given above corresponding the errors Errors:
fz.c: In member function ‘void Huffman::find_two_smallest(Huffman::Node**, Huffman::Node**)’:
fz.c:33:25: error: cannot convert ‘Huffman::Node*’ to ‘Huffman::find_two_smallest(Huffman::Node**, Huffman::Node**)::node*’ in initialization
fz.c:34:22: error: cannot convert ‘Huffman::Node*’ to ‘Huffman::find_two_smallest(Huffman::Node**, Huffman::Node**)::node*’ in initialization
fz.c:39:9: error: invalid use of incomplete type ‘struct Huffman::find_two_smallest(Huffman::Node**, Huffman::Node**)::node’
fz.c:33:8: error: forward declaration of ‘struct Huffman::find_two_smallest(Huffman::Node**, Huffman::Node**)::node’
fz.c:41:11: error: invalid use of incomplete type ‘struct Huffman::find_two_smallest(Huffman::Node**, Huffman::Node**)::node’
fz.c:33:8: error: forward declaration of ‘struct Huffman::find_two_smallest(Huffman::Node**, Huffman::Node**)::node’
fz.c:41:24: error: invalid use of incomplete type ‘struct Huffman::find_two_smallest(Huffman::Node**, Huffman::Node**)::node’
fz.c:33:8: error: forward declaration of ‘struct Huffman::find_two_smallest(Huffman::Node**, Huffman::Node**)::node’
fz.c:48:11: error: invalid use of incomplete type ‘struct Huffman::find_two_smallest(Huffman::Node**, Huffman::Node**)::node’
fz.c:33:8: error: forward declaration of ‘struct Huffman::find_two_smallest(Huffman::Node**, Huffman::Node**)::node’
fz.c:50:11: error: cannot convert ‘Huffman::find_two_smallest(Huffman::Node**, Huffman::Node**)::node*’ to ‘Huffman::Node*’ in assignment
fz.c:51:11: error: cannot convert ‘Huffman::find_two_smallest(Huffman::Node**, Huffman::Node**)::node*’ to ‘Huffman::Node*’ in assignment