eric%bnrmtl%IRO.UMONTREAL.CA@MITVMA.MIT.EDU (06/02/89)
A colleague has a strange problem trying to use libg++ 1.35 streams. He sends me the following description. --------------------------------------------------------------------------- /* Why does third item on line marked "BUG!" (line 27) not get printed? */ #include <stream.h> #include <stdio.h> class counter { private: unsigned int value; public: counter(int init=5); counter( counter& ); ~counter(); unsigned int operator+ (counter); }; main() { int k ; counter c1; counter c2(7); // removing next line will result in core dump instead printf("int = %d\n", k); cout << "BUG! " << (c1+c2) << " Why not printed? \n"; cout << "\n"; // IF preceding/following 2 lines switched, get other results!! k = c1+c2; cout << "No bug " << k << " Printed. \n"; } counter::counter(int init) { value = init; cout << form("constructor %d\n", value); } counter::counter( counter& i ) { value = i.value; cout << form("call-by-value %d\n", value); } counter::~counter() { cout << form("destructor %d \n", value); } unsigned int counter::operator+ (counter other) { return value + other.value; } ---------------------------------------------------------------------------- ---------------------------------------------------------------------------- Eric Brunelle | "C'est la nuit qu'il est beau de croire a la lumiere." BNR-Montreal | -- E. Rostand ----------------------------------------------------------------------------