You have undefined behavior somewhere else in your program -- my guess would be that you actually casted that pointer into a std::istream
, even though it is not. We would need to see where in
is instantiated before being able to run down exactly what's going on. Look for any casts to istream
in your codebase and I bet you find the problem.
views:
94answers:
3
+1
A:
Billy ONeal
2010-09-29 17:20:13
+3
A:
This probably indicates that your is
member does not point to a stringstream
. It might just be initialized to some garbage value when enclosing object is instantiated.
If you are testing for pointer being zero, make sure it's set to zero in the constructor (and reset to zero if you ever detach the stream).
Nikolai N Fetissov
2010-09-29 17:20:45
+1 for pointing out lack of initialization -- that's the most likely cause here.
Billy ONeal
2010-09-29 17:24:20
+4
A:
You've answered the question in the last two lines. You have a dangling pointer to an object that's gone out of scope, and using it will cause undefined behaviour (which could well be a crash). You need to make sure the object exists for as long as it's needed, by placing it in a longer-lasting scope or allocating it with new
and making sure it is deleted when no longer needed.
Mike Seymour
2010-09-29 17:28:19
If allocating with `new`, it should be going into some form of smart pointer, be it `std::auto_ptr`, or some form of scoped or shared pointer.
Billy ONeal
2010-09-29 17:30:40
Or just return a string by value from `.str()`, since all OP does with the pointer is (attempt to) get the data from it.
Potatoswatter
2010-09-29 17:36:28