Xref: utzoo comp.lang.c++:6402 gnu.g++:639 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!pp!cadillac!sunburn!dsouza From: dsouza@mcc.com Newsgroups: comp.lang.c++,gnu.g++ Subject: Stream Manipulators: A Question Message-ID: <6011@cadillac.CAD.MCC.COM> Date: 9 Feb 90 19:44:13 GMT Sender: news@cadillac.CAD.MCC.COM Reply-To: dsouza@mcc.com Distribution: usa Organization: MCC VLSI-CAD Program, Austin, TX Lines: 63 A question about stream manipulators: e.g. cout << "Enter a Number: " << endl ; described in Lippman, p. 378. "endl" is a manipulator: i.e. has some side effects other than simply printing out something -- in this case, print new-line and flush the stream. It is supposed to be implemented as a function which takes an ostream& as an single argument does arbitrary things and returns an ostream&. Manipulators which require additional arguments are more complicated. According to the AT&T C++ 2.0 Library Manual (p 3-18) the following should be sufficient to define a simple manipulator called "tab". SUN C++ accepts it, g++ 1.36.4 wont compile it, complaining it "cannot resolve overloaded function `tab' based on non-function type". 1. What does this error message mean ? 2. Is this a bug in g++, or is it not a part of the 2.0 language specification? Thanks Desmond. //--------------------- begin ------------- #include ostream& tab(ostream& o) { return o << "\t"; } main () { cout << 1 << tab << 2 << tab << 3 ; } //--------------------- end ------------- Here is what g++ does: optima% g++ -v manip.cc g++ version 1.36.4 (based on GCC 1.36.93) /usr/local/gnu/1.36.4/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ manip.cc /usr/tmp/cca17706.cpp GNU CPP version 1.36.92 /usr/local/gnu/1.36.4/lib/gcc-cc1plus /usr/tmp/cca17706.cpp -quiet -dumpbase manip.cc -g -version -o /usr/tmp/cca17706.s GNU C++ version 1.36.4 (based on GCC 1.36.93) (sparc) compiled by GNU C version 1.36.92. default target switches: -mfpu -mepilogue manip.cc: In function int main (): manip.cc:8: cannot resolve overloaded function `tab' based on non-function type manip.cc:8: type conversion required for type `ostream' optima% And here is SUN C++: optima% CC manip.cc CC manip.cc: cc -I/net/sunspot/usr/cadsw/CC/sun4/incl manip.c -L/net/sunspot/usr/cadsw/CC/sun4/ -lC optima% optima% a.out 1 2 3 optima% ------------------------------------------------------------------------------- Desmond D'Souza, MCC CAD Program | ARPA: dsouza@mcc.com | Phone: [512] 338-3324 Box 200195, Austin, TX 78720 | UUCP: {uunet,harvard,gatech,pyramid}!cs.utexas.edu!milano!cadillac!dsouza