I created a templated BST with function to collect data:
typedef void (*func)(T&);
...
template<class T>
void BST<T>::inorderCollectionTraversal(func f) const
{
inorderCollection(root,f);
}
template<class T>
void BST<T>::inorderCollection(node<T> *p, func f) const
{
if(p!=NULL){
inorderCollection(p->leftPtr, f);
f(p->data);
inorderCollection(p->rightPtr, f);
}
}
And then in another class, I tried to use this data structure to sort objects of another class. I am unable to extract the objects from the BST:
map<string, BST<Weather> > dataByMonth;
dataByMonth.find(monthCount[i]+eYear)->second.inorderCollectionTraversal(collectData); // the error points to this line
void Query::collectData(Weather& w){
collector.push_back(w);
}
Everything else was tested with no issue. Only this is not working. The error message is :
No matching function for call to 'BST<Weather>::inorderCollectionTraversal(<unresolved overloaded function type>)
candidate: void BST<T>::inorderCollectionTraversal(BST<T>::func) const [with T
error: no matching function for call to 'BST<MetData>::inorderCollectionTraversal(<unresolved overloaded function type>)'|
include\BST.h|235|note: candidate: void BST<T>::inorderCollectionTraversal(BST<T>::func) const [with T = MetData; BST<T>::func = void (*)(MetData&)]|
include\BST.h|235|note: no known conversion for argument 1 from '<unresolved overloaded function type>' to 'BST<MetData>::func {aka void (*)(MetData&)}'|
Can anyone advise where I went wrong?
BST::inorderCollectionTraversal(), which was not given any arguments, and does not exist.