albero_binario1.cpp: In member function ‘void btree::insert(int)’:
albero_binario1.cpp:34:18: error: lvalue required as left operand of assignment
albero_binario1.cpp:39:15: error: request for member ‘insert’ in ‘((btree*)this)->btree::right’, which is of non-class type ‘btree*’
albero_binario1.cpp:41:14: error: request for member ‘insert’ in ‘((btree*)this)->btree::left’, which is of non-class type ‘btree*’
void btree::insert(int key1)
if (this==NULL) // Impossible. The object whose method you call cannot be in address NULL
this=new btree(); // Error. This exists. Overwriting is not permitted
this->right.insert(key1); // right is a pointer. Dereference with ->
// You will still fail, because 0==right
// EDIT: not really 0, but undefined. An uninitialized pointer.
this->left.insert(key1); // left is a pointer. Dereference with ->
// You will still fail, because 0==left
Consider this instead (and what does it require from class btree):
1 2 3 4 5 6 7
btree * root = new btree(5);
Remember the copy constructor, copy assignment, and destructor.
What is the state of the tree before insert is called?
When the insert() of a node on a tree is called, what possibilities there are?
What should the state of the tree be after the insertion has completed?