This is just a snippet of the uncommented code. The packing vector keeps causing an error at the push_back(), and I'm not quite sure why:
EDIT: It has been updated to say
vector<BinTreeNode<HuffmanToken<Pixel>* > > packing = new vector<BinTreeNode<HuffmanToken<Pixel> > >();
however, there is still the allocator error even with the adjusted templates.
no matching function to call std::vector , std::allocator>> :: push_back(BinTreeNode>>&
BinTree<HuffmanToken<Pixel> >* Huffman::buildTree(const vector<HuffmanToken<Pixel>>& tokens) {
BinTreeNode<HuffmanToken<Pixel> >* g1 = new BinTreeNode<HuffmanToken<Pixel> >();
BinTreeNode<HuffmanToken<Pixel> >* g2 = new BinTreeNode<HuffmanToken<Pixel> >();
BinTreeNode<HuffmanToken<Pixel> >* g3 = new BinTreeNode<HuffmanToken<Pixel> >();
vector<HuffmanToken<Pixel> > packing ;
vector<HuffmanToken<Pixel> >::const_iterator it;
it = tokens.begin();
for(int i = 0; i < tokens.size(); i++) {
g1 -> setValue(tokens.at(i));
packing.push_back(g1);
}
5 Answers 5
Your vector is expecting HuffmanToken<Pixel> objects, but you're trying to push_back a BinTreeNode<HuffmanToken<Pixel> >* pointer. Just make sure your vector has the right template type.
Edit
Considering your update, I decided to throw up all the code as it should be:
BinTree<HuffmanToken<Pixel> >* Huffman::buildTree(const vector<HuffmanToken<Pixel>>& tokens) {
BinTreeNode<HuffmanToken<Pixel> >* g1 = new BinTreeNode<HuffmanToken<Pixel> >();
BinTreeNode<HuffmanToken<Pixel> >* g2 = new BinTreeNode<HuffmanToken<Pixel> >();
BinTreeNode<HuffmanToken<Pixel> >* g3 = new BinTreeNode<HuffmanToken<Pixel> >();
vector<BinTreeNode<HuffmanToken<Pixel> >*> packing ;
vector<BinTreeNode<HuffmanToken<Pixel> >*>::const_iterator it;
it = tokens.begin();
for(int i = 0; i < tokens.size(); i++) {
g1 -> setValue(tokens.at(i));
packing.push_back(g1);
}
The only difference from the original code is that vector<HuffmanToken<Pixel> > is replaced with vector<BinTreeNode<HuffmanToken<Pixel> >*> (that goes for the vector itself, as well as the iterator).
2 Comments
vector<BinTreeNode<HuffmanToken<Pixel>* > > packing;.Your types don't match. You have a vector of HuffmanToken<Pixel>s and you're trying to push a BinTreeNode<HuffmanToken<Pixel> > * onto it.
Comments
BinTreeNode<HuffmanToken<Pixel> >* g1 = new BinTreeNode<HuffmanToken<Pixel> >();
The type of g1 is BinTreeNode<HuffmanToken<Pixel> >* i.e., it is a pointer type. But packing is of type vector<HuffmanToken<Pixel> >. What the vector holds is objects but not pointers to objects.
1 Comment
Your vector is of type HuffmanToken<Pixel> but you are trying to push type
BinTreeNode<HuffmanToken<Pixel> >* into it.
Comments
The problem here is that you are creating a vector that is supposed to hold items of type HuffmanToken<Pixel>. Instead of pushing items of that type into the vector, you try to push in a BinTreeNode<HuffmanToken<Pixel> >*.
And this cannot work.
What you probably wanted to push was the return value of g1->getValue() (if there is such a method at all...).