Hi Andy - I'm no expert on the STL, but this code does produce the expected (to me, anyway) output of 42, 43, 42: #include <vector> #include <iostream> int main() { std::vector<int> foo; std::vector<int>::const_iterator iter1; // a const_iterator can be used to traverse a non-const object: foo.push_back(42); foo.push_back(43); for(iter1 = foo.begin(); iter1 != foo.end(); ++iter1) std::cout << *iter1 << '\n'; // can assign an iterator to a const_iterator directly: std::vector<int>::iterator iter2...
This code doesn't compile, despite 'root' being overloaded to return both an iterator and a const_iterator: ntree<foo>bar; ntree<foo>::iterator iter = bar.root(); // Ok ntree<foo>::const_iterator iter = bar.root(); // not Ok Similarly, a conversion from an iterator to a const_iterator doesn't compile: ntree<foo>::iterator iter1 = bar.root(); ntree<foo>::const_iterator iter2 = iter1; Any ideas? Thanks.
Invalid hierarchical reference does not generate error