(For your information, I have VC2003.NET)
I've just rolled and tested my own smart pointer, and it was working perfectly under all tests until I tested it inside of a std::vector.
This is when it starts getting weird. From what I know, operator -> keeps applying itself to the returned result until the return result has no operator ->, and it evaluates to that result. Here's what's happenning.
The operator -> applied to an iterator stops applying itself when it gets to my smart pointer. So I have to dereference the vector and then call operator ->.
After doing that, I get an access violation inside of my operator ->. That didn't make sense to me, because it was working fine before. So, I put a break-point in the code, ran it in debugger, and put the pointer in the 'watch' list. From inside of the member function, the symbol isn't found! At any other point in the code, if I call operator ->, the symbol *is* found, but if I call it from a dereferenced iterator, it isn't! Why would that be happenening? It makes absolutely no sense, and I'll bet it's connected to why I'm getting an access violation.
Quote:This is when it starts getting weird. From what I know, operator -> keeps applying itself to the returned result until the return result has no operator ->, and it evaluates to that result. Here's what's happenning.
Incorrect, operator-> re-applies itself until the returned value is a pointer.
Quote:and I'll bet it's connected to why I'm getting an access violation.
You gave the code for your class. Fine. Give a complete snippet of code that triggers that access violation - so that I can compile and test it.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
You forgot to initialize the iterator t. Adding t = v.begin() to the loop fixes that.
You have to add the dereference because std::vector<T>::iterator::operator->() does return a pointer to T, stopping the chain.
Thread moved as requested.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan