Well, I was having terrible difficulties with some C++ code. I had a template class, and a template class which inherited that first template class. I named them simpleStream and arrayStream (arrayStream inherited simpleStream), and I'll explain what they were for later.
The problems were all based around one thing: virtual functions. I had a function, simpleStream::next(), which would be overloaded by arrayStream::next(). In addition, an operator for simpleStream (the >> operator) called upon simpleStream::next().
Now, if everything were working perfectly, then if I passed an arrayStream to a function expecting a simpleStream (which should work as arrayStream is inherited from simpleStream) and then that function called the >> operator on what it thought was a simpleStream, it would still end up calling arrayStream::next(). Unfortunately, not everything was working properly.
Funnily enough, it was all the fault of one little thing. I was not passing the arrayStream object to the function expecting the simpleStream. I was instead (from the compiler's point of view) passing the value of the object, which was then copied (by C++) to the simpleStream object. Meaning it was no longer an arrayStream object at all.
The solution, of course, was to pass by reference instead of by value. Once I did that, everything was fixed.
The simpleStream and arrayStream objects were meant to act similarly to cin or ifstreams, but wrap an array instead of standard input or a file. (Incidentally, I also wrote one which uses a file, a very simple wrapper around ifstream). I wanted to be able to read both arrays and files without having to have separate logic to interpret each. It was, perhaps, overkill to do it this way, but I learned a lot.