In my code I have a vector that should be a size of 1, containing the integer value 2.
When this portion of the code runs:
and the output is as I expect:Code:std::cout << "Root size: " << root->key.size() << "\n"; typename std::vector<T>::iterator it = root->key.begin(); for(; it != root->key.end(); ++it){ std::cout << *it << " "; }
But when I have this in my code:Code:Root size: 1 2
This is the output:Code:Node* curr = root; std::cout << curr->key[0] << "\n"; std::cout << curr->key[1] << "\n"; std::cout << curr->key[2] << "\n";
So what's with the extra "2" in the output?Code:2 2 0
Is it because operator[] returns a reference and perhaps it's referencing some erroneous data? I'm confused because the size() is correct and the iterator display works correctly...
I'm preplexed...
BTW: replacing curr->key[x] with root->key[x] makes no difference, curr doesn't point to anything else in the function either.