Im doing my homework, and I have hard time figuring out one thing. I'm suppose to write BST that can work with integer or with float. And for such and practicing we have different header files for integer, float and the tree itself.
I'm trying to create a way for a function to run based of which type I'm currently working with [int/float] without having to write it twice. so I got something like this:
void addItemToTree(BST* bst, void* val)
{
#ifdef IsInt
addItemToTreeRec(bst->head, *((int*)val));
#else
addItemToTreeRec(bst->head, *((float*)val));
#endif
}
so far no problems, it leads to:
#ifdef IsInt
void addItemToTreeRec(node* my_node, int val)
#else
void addItemToTreeRec(node* my_node, float val)
#endif
{
-- function itself ---
}
but the problem is, the header file that contains all integer related struct and declaration do not recognize my function while the float header file does.
I figured it has to do something with the way I lay the ifdef
down but I cannot seems to solve it without having to copy the whole code and put it before #else