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:
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 << " ";
}
and the output is as I expect:
But when I have this in my code:
Code:
Node* curr = root;
std::cout << curr->key[0] << "\n";
std::cout << curr->key[1] << "\n";
std::cout << curr->key[2] << "\n";
This is the output:
So what's with the extra "2" in the output?
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.