Type Conversion Error

Hi. I'm working on making a program for generating Huffman code. I'm using my version of a priority queue, which has already been tested. I'm getting a conversion error when trying to add new nodes to the queue. I'm not sure if this means I need a dereference operator for the nodes or if I shouldn't use pointers in the while loop. Any insight is appreciated.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void HuffTree::buildTree(char * chs, int * freqs, int size){
  PQueue <HuffNode, 100>que;
  for( int i = 0; i < size; i++ ){
    que.insert( new HuffNode( 0, 0, chs[i], freqs[i] ) );
  }


  while( que.size() > 1 ){
    HuffNode * firstSmallest = que.findMin();
    que.deleteMin();
    firstSmallest->code = "0" + firstSmallest->code;
    HuffNode * secondSmallest = que.findMin();
    que.deleteMin();
    secondSmallest->code = "1" + secondSmallest->code;

    que.insert( new HuffNode( firstSmallest, secondSmallest, firstSmallest->freq + secondSmallest->freq, '\0' ) );
  }
  _root = que.findMin();
}



1
2
3
4
5
6
7
8
9
10
11
12
g++ -c HuffTree.cpp
HuffTree.cpp: In member function ‘void HuffTree::buildTree(char*, int*, int)’:
HuffTree.cpp:12:44: error: cannot convert ‘HuffNode’ to ‘HuffNode*’ in initialization
     HuffNode * firstSmallest = que.findMin();
                                            ^
HuffTree.cpp:15:45: error: cannot convert ‘HuffNode’ to ‘HuffNode*’ in initialization
     HuffNode * secondSmallest = que.findMin();
                                             ^
HuffTree.cpp:21:23: error: cannot convert ‘HuffNode’ to ‘HuffNode*’ in assignment
   _root = que.findMin();
                       ^
make: *** [makefile:6: HuffTree.o] Error 1

Last edited on
What does findmin() return?
The Huffnode with the smallest freq.
findMin is returning a HuffNode but you are accepting it into a HuffNode*. Probably findMin should return a HuffNode*.
Topic archived. No new replies allowed.