I have a problem with my C ++ pointers, and it would be great if someone could share their experiences with me!
The output I get is:
1: 2: END: C 1:C 2:E END: E
Expected Result:
1: 2: END: C 1:C 2:C END: E
The relevance code is as follows:
my test.cpp
tree.insert('C'); tree.insert('E');
Insert Function:
template <typename T> pair<typename btree<T>::iterator, bool> btree<T>::insert(const T& elem) { cout << "1:" << this->rbegin_->value() << endl; btree_node<T> node(elem); cout << "2:" << this->rbegin_->value() << endl; rbegin_ = &node; iterator itr; pair<typename btree<T>::iterator, bool> p(itr, false); cout << "END: " << this->rbegin_->value() << endl; return p; }
Constructor for btree_node (which is mostly empty):
template <typename T> btree_node<T>::btree_node(const T& elem) : value_(elem), nextCont_(NULL), prevCont_(NULL), nextNode_(NULL), prevNode_(NULL) {}
The btree class has a private variable:
btree_node<T>* rbegin_;
This is what I am changing. Initially, rbegin_ is set to an empty node constructor in the btree constructor with:
btree_node<T> end(NULL); rbegin_ = &end;
It looks like my node constructor, which does nothing, modifies the value of rbegin-> value () ....
Any help was appreciated.