Not sure how to call a class function using templates
c++, templates
Solution
You can get some inspiration from standard library functions like `find_if` that has an extra parameter for the comparison.
template <class InputIterator, class Predicate>
InputIterator find_if ( InputIterator first, InputIterator last, Predicate pred );
You can then pass a parameter telling the `search` function how to find the key you are looking for. Perhaps replace the use of `==` with
if(pred(temp[index]->data, key)) { @things happen }
and pass different `pred` functions for comparing the key to the appropriate member.
Problem
I am making my own dictionary using templates (no I can't and I won't use anything from STL). I want to have a very simple search function, but I have a small problem. ``` template <typename TElement> void Dictionary<TElement>::search(TElement ADT, int key) { // Abstract Data Type inf flag = 0; index = int (key % max); temp[index] = root[index]; // root of the hash while (temp[index]->next != NULL) { if(temp[index]->data->key_actual_name == key) { @things happen } } } ``` What I want to understand: how to use template so that I can have `temp[index]->data-><template call>` if that makes any sense I want to call the dictionary by using: Class_type == TElement and "key" is always an int but it can be different things. It might be an ID or phone number. Problem is I need to use the actual name of the key (`if(temp[index]->data->ID (or phone or what ever) == key`) { @things happen }), I imagine I could use templates here but I don't know how. also maybe relevant: ``` template <typename TElement> typedef struct list{ TElement data; struct list *next; }node_type; node_type *ptr[max], *root[max], *temp[max]; ``` Also, if I do use a template for key_actual_name, how would the implementation work AND how would I call that function ?