ostream::operator<< overloading is causing the address to be printed
807575Aug 19 2003 — edited Aug 29 2003Hi,
I am getting the a strange result when I overload the operator << (const char*). It prints out the address of the string instead of the value.
I am using CC 5.3
CC -library=rwtools7_std testMYStream.C
It works fine if I use CC -library=rwtools7,iostream testMYStream.C
However since I use roguewave and STL, I need the rwtools_std flag.
Is this a bug in my code or in the compiler ?
My version strings are
138> CC -V
CC: Sun WorkShop 6 update 2 C++ 5.3 2001/05/15
139> uname -a
SunOS eiffel 5.8 Generic_108528-06 sun4u sparc SUNW,Sun-Blade-100
In /usr/lib
version of "libCrun.so.1": libC Patch 108434-13 2003/06/03
version of "libCstd.so.1": libC Patch 108434-13 2003/06/03
// -----------------------------
// File testMYStream.C
#include "MYfstream.h"
int
main(int argc, char* argv[]) {
MYfstream foo("data.dat",ios::out);
foo << "I should be readable\n";
foo.close();
return 0;
}
// -----------------------------
// File MYfstream.h
#include <fstream.h>
class MYfstream : public fstream {
public:
// Constructors/destructor
MYfstream ();
MYfstream (const char* str,int mode);
~MYfstream (void) { this->close();};
// Redeclaration of the insertion operator.
virtual MYfstream & operator << (const char* str);
};
inline MYfstream &
MYfstream::operator << (const char* s) {
if ( fstream::operator<<(s)) { // is there an issue here ?
return *this;
} else
throw;
}
// Constructors
MYfstream::MYfstream () : fstream() { };
MYfstream::MYfstream (const char* str,int mode) : fstream(str,mode)
{
};
#endif