🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #738

manipulators for class derived from ostream?

#738
From: Blue Sky Tours
Date: Tue, 22 Aug 1995 20:41
76 lines
2191 bytes
I wish to define a manipulator for a class which is derived from
ostrstream.  There does not seem to be a way to do this.

For example, I have the following def:

class Mail : public ostrstream {
private:
  char       recip[32];

  istream    messages;
  string     buffer;
  string     app_name;

public:
  Mail(void);
  Mail(char *to, string name);
  ~Mail();

  int init(char *to, string name);
  void recipient(char *to);
  void send(char *subject);
  int load_buffer(void);
  void clear(void);
  void endmsg(void);
};

This class works just fine, but I have to explicitly call
mail.send(), to actually have my message sent:

mail << "Hello";
mail.send("testing");

I would much rather be able to have it work like so:

mail << "Hello" << send("testing");

When I try to define a manipulator like:

Mail &send(Mail &os, char *str)
{
  // send the message...
}

GCC 2.6.3 and GCC 2.7.0 complain:

warning: converting `Mail & ()(Mail &)' to `ios & ()(ios &)' is a 
contravariance violation

If I try to define the manipulator like:

ostream &send(ostream &os, char *str)
{
  // send the message...
  // attempt to access messages variables from the Mail class here.
}

Then the compiler says that the manipulator is ok, but that ostream
does not have a ``messages'' variable.

So, how do I tell the compiler that I wish to access a variable in my
Mail class from an ostream manipulator?

I am greatfull to anyone who can give me some insight into this
problem,

John


--

|         |
+--+  ==  |  John Patrick Poet          Blue Sky Tours
|  |      |  System Admin/programmer    10832 Prospect Ave., N.E.
|     +---+  john@BlueSkyTours.COM      Albuquerque, N.M. 87112
|     |                                 505 292 6961
Technical Details
Message-ID: <41dfe5$9m7@mack.rt66.com>
Path: arc1-ca.pugleaf.net!mack.rt66.com!not-for-mail

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!mack.rt66.com!not-for-mail
From: poet@mack.rt66.com (Blue Sky Tours)
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: manipulators for class derived from ostream?
Date: 22 Aug 1995 14:41:41 -0600
Organization: Engineering International Inc., Public Internet Access
Message-ID: <41dfe5$9m7@mack.rt66.com>
NNTP-Posting-Host: mack.rt66.com
X-Newsreader: TIN [version 1.2 PL2]