I am working on homework using a binary search tree. My professor provided us with files to modify and add two methods to one of the files. The 2 new methods are called void find_node( const T &val ) and void delete_node( Node< T > *&p ). I have some code written out, but when I try to compile it, I receive error messages saying that cannot convert parameter 1 from Node<T>* to const int* Wondering if anyone could help me with this.
btree.h(76): error C2664: 'Node<T>::find_node' : cannot convert parameter 1 from 'Node<T> *' to 'const int &'
with
[
T=int
]
Reason: cannot convert from 'Node<T> *' to 'const int'
with
[
T=int
]
Not sure how I would do that. Sorry, I am new to this programming. I also think my cpp files would be helpful, but I dont have room in the above code to add it in. Actually, I will add one of the cpp files in because I get another error in the cpp file. I will put here in this comment.
here are all of the errors that came up. pretty much the same amount as before. I just didn't copy all of them. But here is all of the errors:
tree2.cpp
1>c:\users\owner\documents\visual studio 2010\projects\bst\bst\node.h(168): error C2664: 'Node<T>::find_node' : cannot convert parameter 1 from 'const int' to 'Node<T> *'
1> with
1> [
1> T=int
1> ]
1> Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1> c:\users\owner\documents\visual studio 2010\projects\bst\bst\node.h(167) : while compiling class template member function 'void Node<T>::find_node(Node<T> *,const T &) const'
1> with
1> [
1> T=int
1> ]
1> c:\users\owner\documents\visual studio 2010\projects\bst\bst\btree.h(65) : see reference to class template instantiation 'Node<T>' being compiled
1> with
1> [
1> T=int
1> ]
1> c:\users\owner\documents\visual studio 2010\projects\bst\bst\btree.h(62) : while compiling class template member function 'void BinaryTree<elemType>::insert(const elemType &)'
1> with
1> [
1> elemType=int
1> ]
1> c:\users\owner\documents\visual studio 2010\projects\bst\bst\tree2.cpp(28) : see reference to class template instantiation 'BinaryTree<elemType>' being compiled
1> with
1> [
1> elemType=int
1> ]
1>c:\users\owner\documents\visual studio 2010\projects\bst\bst\node.h(171): error C2660: 'Node<T>::delete_node' : function does not take 2 arguments
1> with
1> [
1> T=int
1> ]
1> tree1.cpp
1>c:\users\owner\documents\visual studio 2010\projects\bst\bst\node.h(168): error C2664: 'Node<T>::find_node' : cannot convert parameter 1 from 'const std::string' to 'Node<T> *'
1> with
1> [
1> T=std::string
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> c:\users\owner\documents\visual studio 2010\projects\bst\bst\node.h(167) : while compiling class template member function 'void Node<T>::find_node(Node<T> *,const T &) const'
1> with
1> [
1> T=std::string
1> ]
1> c:\users\owner\documents\visual studio 2010\projects\bst\bst\btree.h(65) : see reference to class template instantiation 'Node<T>' being compiled
1> with
1> [
1> T=std::string
1> ]
1> c:\users\owner\documents\visual studio 2010\projects\bst\bst\btree.h(62) : while compiling class template member function 'void BinaryTree<elemType>::insert(const elemType &)'
1> with
1> [
1> elemType=std::string
1> ]
1> c:\users\owner\documents\visual studio 2010\projects\bst\bst\tree1.cpp(28) : see reference to class template instantiation 'BinaryTree<elemType>' being compiled
1> with
1> [
1> elemType=std::string
1> ]
1>c:\users\owner\documents\visual studio 2010\projects\bst\bst\node.h(169): error C2451: conditional expression of type 'const std::string' is illegal
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\users\owner\documents\visual studio 2010\projects\bst\bst\node.h(171): error C2660: 'Node<T>::delete_node' : function does not take 2 arguments
1> with
1> [
1> T=std::string
1> ]
1>c:\users\owner\documents\visual studio 2010\projects\bst\bst\node.h(168): error C2664: 'Node<T>::find_node' : cannot convert parameter 1 from 'const int' to 'Node<T> *'
This error is the opposite of what it was before. Are you absolutely sure you did not change the order of parameters where the function was called? Paste your code again, please (I know this is getting boring, sorry)
oh, i didn't realize that one. I'm sure I didn't change anything. I will paste the node.h and btree.h there again. I'll replace it there at the top. also, if this helps, when i sent my code to my professor, he gave this remark back for my find_node function.
Your find_node in your node.h needs to have two arguments.
You've got one (the val that you are searching for), but you should also be receiving the pointer to the node to start searching with.
Initially, that is the root.
find_node should be a binary search, that decends down the left or right side of the tree, executing itself until val == p->value(), when it deletes p and leaves.