This is a simple class and a simple test function:
#include <queue> #include <string> namespace { using namespace std; } class NameStream { queue<string> stream; public: string operator * () { return stream.front(); } NameStream &operator ++(int) { stream.pop(); return *this; } NameStream &operator ++() { stream.pop(); return *this; } NameStream &operator <<(string name) { stream.push(name); } operator bool() { return !stream.empty(); } }; inline void nameStreamTest() { NameStream &stream = *new NameStream; stream << "hi" << "hey" << "hoy"; while (stream) { printf("%s\n", (*stream++).c_str()); } }
He falls in
NameStream &operator <<(string name) { stream.push(name); }
inside the push queue procedure, here is the stack outside of my code:
#0 0x000b5079 in std::deque<std::string, std::allocator<std::string> >::push_back at stl_deque.h:1055 #1 0x000b50f2 in std::queue<std::string, std::deque<std::string, std::allocator<std::string> > >::push at stl_queue.h:204 #2 0x000b511c in NameStream::operator<< at NameStream.h:24 #3 0x000b520f in nameStreamTest at NameStream.h:32
In this case, my experience does not work. What am I doing wrong?
PS :.
NameStream &stream = *new NameStream;
Used to delete a location
stream
an object at the address (offset?) 0x7d (!), which raises the same exception.
source share