C
cedarmillxing215
The oddness is on the last line of code. This is stripped down as far
as I could figure, and I provide several similar examples that work as
expected. I have no idea whether this is a compiler bug or my not
understanding how the << overload is chosen.
-Chris
--------------------
#include <iostream>
#include <sstream>
ostringstream get()
{
return ostringstream();
}
class my_ostringstream : public ostringstream
{
public:
static my_ostringstream get() { return my_ostringstream(); }
~my_ostringstream() { cout << str() << endl; }
};
int main(int argc, char * argv[])
{
ostringstream var1;
var1 << "text 1";
cout << var1.str() << endl; // Output: text 1
ostringstream var2("text 2");
cout << var2.str() << endl; // Output: text 2
ostringstream var3 = get();
var3 << "text 3";
cout << var3.str() << endl; // Output: text 3
{
my_ostringstream var4;
var4 << "text 4";
} // Output: text 4
{
my_ostringstream var5 = my_ostringstream::get();
var5 << "text 5";
} // Output: text 5
{
my_ostringstream::get() << "text 6"; // WTF, seems to be treated
as a void *
} // Output: 00417800
}
as I could figure, and I provide several similar examples that work as
expected. I have no idea whether this is a compiler bug or my not
understanding how the << overload is chosen.
-Chris
--------------------
#include <iostream>
#include <sstream>
ostringstream get()
{
return ostringstream();
}
class my_ostringstream : public ostringstream
{
public:
static my_ostringstream get() { return my_ostringstream(); }
~my_ostringstream() { cout << str() << endl; }
};
int main(int argc, char * argv[])
{
ostringstream var1;
var1 << "text 1";
cout << var1.str() << endl; // Output: text 1
ostringstream var2("text 2");
cout << var2.str() << endl; // Output: text 2
ostringstream var3 = get();
var3 << "text 3";
cout << var3.str() << endl; // Output: text 3
{
my_ostringstream var4;
var4 << "text 4";
} // Output: text 4
{
my_ostringstream var5 = my_ostringstream::get();
var5 << "text 5";
} // Output: text 5
{
my_ostringstream::get() << "text 6"; // WTF, seems to be treated
as a void *
} // Output: 00417800
}