template<class _TYPE, class _VAL_TYPE>
bbst<_TYPE, _VAL_TYPE>::~bbst ()
{
if (this->left != nullptr) delete *this->left;
if (this->right != nullptr) delete *this->right;
}
I am attempting to use this function to dissasemble an entire binary search tree, however, i cant seem to access this->left which is a pointer to bbst<_TYPE, _VAL_TYPE>
it says:
error C2440: 'delete' : cannot convert from 'st::bbst<_TYPE,_VAL_TYPE>' to 'void *'
Don't dereference the pointer. You also don't need to check if the pointer is a null pointer because deleting a null pointer is safe and will do nothing.
i tried that, it still gave the same error, i found out that the destructor cant be recursive for some reason, when i did the same thing via a recursive function calling the destructor it worked, and im trying to delete the value of the pointer's address not the pointer itself
@Peter: If you delete a null pointer nothing happens by design.
@GFreak: I hope you're not REALLY defining your functions like that...did you know that templated class functions have to be defined inline? Otherwise you have to explicitly instantiate the templates for the linker to fi8nd them.
@Peter i know, every single node besides the root are created dynamically, anyway i finished it and it works, not sure how i would submit it for public use though
The library i made was a balanced binary search tree capable of sorting classes or any type of object using a user defined function
ie:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <searchtree>
class a
{
public:
a (int x) : value(x) {};
private:
staticint GetValue (a obj)
{
return obj->value;
}
static bbst<a, int> searchTree (GetValue);
int value;
}
You have not seen the code yet and it does work I have been testing it
The reason why that method is static is because the function used to determine the number value of an object takes _TYPE and returns _VAL_TYPE, it could have been non-static outside of the class, it does not matter but it MUST have that type and parameter
Just because you don't understand templates does not mean its not possible