Xref: utzoo comp.lang.c++:6413 gnu.g++:645 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!rice!brazos!rich From: rich@Rice.edu (Rich Murphey) Newsgroups: comp.lang.c++,gnu.g++ Subject: Re: Stream Manipulators: A Question Message-ID: Date: 10 Feb 90 19:17:24 GMT References: <6011@cadillac.CAD.MCC.COM> Sender: root@rice.edu Followup-To: comp.lang.c++ Distribution: usa Organization: Department of Electrical and Computer Engineering, Rice University Lines: 44 In-reply-to: dsouza@mcc.com's message of 9 Feb 90 19:44:13 GMT Desmond D'Souza asks about stream manipulators: 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". //--------------------- begin ------------- #include ostream& tab(ostream& o) { return o << "\t"; } main () { cout << 1 << tab << 2 << tab << 3 ; } //--------------------- end ------------- Perhaps this is naive, but the definition of tab as a function and it's use as a variable are confusing. It seems like you want to create an object which prints a tab when output to a stream. One solutiong to your problem in g++ might be: #include class Tab { public: friend ostream& operator << (ostream&, const Tab&); }; inline friend ostream& operator << (ostream& out, const Tab& p) { return out << "\t"; } Tab tab; main () { cout << 1 << tab << 2 << tab << 3 ; } Hope that helps, -- Rich@rice.edu