Hi,

I'm having a problem with overloading std::stringstream.
What I'm trying to achieve is a stringstream that is instantiated only as a temporary and outputs its content on destruction.

Here is the code:

Code:
#include <iostream>
#include <sstream>

class stupidostream : public std::ostringstream {
public:
        stupidostream() : std::ostringstream() { }
        stupidostream(const stupidostream& reference) : std::ostringstream() { }
        virtual ~stupidostream() { std::cout << "\""<< this->str() << "\"" << std::endl; }
};


stupidostream getStream()
{
        return stupidostream();
}


int main()
{
        getStream() << "Hello" << " World";
}
What happens is: getStream creates a new stupidostream (which in theory is copied but the compiler should optimise that away).
Then two strings are inserted into the stream. At the ; the stream loses scope, its destructor gets called and the content is displayed.

The expected behaviour of the above therefore is that "Hello World" is displayed, but instead it says "0x80494e8 World" or some other memory address. This means the character pointer is interpreted as an address instead of a c-string.
Since I didn't overload the << operator, the first shift returns a reference to regular std::ostringstream (or one of its base classes) and " World" is inserted properly.
But why? If I insert a std::string or a number first, everything works as expected.
If I overwrite operator<<(const char*), everything works as expected, but in the above example, the compiler chooses the wrong overloaded operator<<.
This happens in both gcc and visual c++, so it has to be a problem in my code...