!!!
OpenStream doesn't return a my_stream object downcast to TStream - it returns a TStream! You can't cast it into my_stream. You can attempt to cast TStream to my_stream - that's why it compiles - but it won't work unless that TStream is a downcast my_stream.
There's a stream factory list in OpenStream (check the code), but if you're only extending TStream then that's useless, because it'll return a TStream before anything else.
I'm not really sure at all how to have access to an extended stream object without creating it yourself.
OpenStream doesn't return a my_stream object downcast to TStream - it returns a TStream! You can't cast it into my_stream. You can attempt to cast TStream to my_stream - that's why it compiles - but it won't work unless that TStream is a downcast my_stream.
There's a stream factory list in OpenStream (check the code), but if you're only extending TStream then that's useless, because it'll return a TStream before anything else.
I'm not really sure at all how to have access to an extended stream object without creating it yourself.