I am working on a school project and have run into a serious roadblock. The project involves making a database using a Binary Search Tree (BST provided for us), which I have done. I am now trying to write search methods. The solution encouraged by the professor is to code:
filmDatabaseBST.inorderTraverse(studioTest);
where filmDatabaseBST is the database (containing Film objects), and studioTest
is the method being passed.
void FilmDatabase::studioTest(Film& anItem)
{
string s; //temporary variable to hold studio from Film
s = anItem.getStudio(); //
if (s == findStudio) //if the search term and the Films studio match
{
Film tempFilm = filmDatabaseBST.getEntry(anItem); //copy Film object and display the data
display(tempFilm);
searchResult = true; //set check to true to indicate a result was found
}
studioTest()
is currently a public method within the class. When I attempt this is get the following error:
FilmDatabase.cpp:209:49: error: no matching function for call to 'BinarySearchTree<Film>::inorderTraverse(<unresolved overloaded function type>)'
I should add that using
filmDatabase.inorderTraverse(display);
works perfectly calling the following method at each node and printing the data from the object stored there.
void display(Film& anItem)
{
anItem.printFilm();
}
The only difference is display()
is not defined in the .h file, and not assigned the FilmDatabase:: namespace. I've attempted similar with studioTest()
but I get the same errors.
Can anyone give me a push in right direction? I'm fairly new as a programmer and with C++, and this is my first post so I apologize if crucial information is missing. Please let me know if that is the case and I'll provide/explain whatever I can.
Note: I've done as much research as I can but all results I've found are issues with the BST code itself, which I've been repeatedly assured is clean and I'm not supposed to alter. Other students have been successful in implementing our professors advice, so there must be a way to make it work.
EDIT: The sum of my problem was that they needed to be free functions, as kindly pointed out by Zan Lynx in the answer below. After altering the program to allow for that, it all works perfectly. Thank you very much for the help!