home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14341 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: ix.netcom.com!news
  2. From: jlilley@ix.netcom.com (John Lilley)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [HELP] ostream inheritance Q?
  5. Date: 29 Mar 1996 18:24:25 GMT
  6. Organization: Netcom
  7. Message-ID: <4jh9sp$1gp@dfw-ixnews6.ix.netcom.com>
  8. References: <4jf4lc$t8l@ground.cs.columbia.edu>
  9. NNTP-Posting-Host: den-co10-17.ix.netcom.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-NETCOM-Date: Fri Mar 29 12:24:25 PM CST 1996
  13. X-Newsreader: WinVN 0.99.7
  14.  
  15. In article <4jf4lc$t8l@ground.cs.columbia.edu>, jean@news.cs.columbia.edu says...
  16. >
  17. >
  18. >        i'm trying to come up with new output stream, say Nostream,
  19. >which provides some more functionality beyond ostream as follows.
  20. >
  21. >--------------------------------------------------
  22. >class Nostream : public ostream {
  23. >public:
  24. >        Nostream(streambuf *sb) : ios(sb) {}
  25. >        ~Nostream() {}
  26. >
  27. >        Nostream& foo(const char *msg) {
  28. >            return *this << mime;
  29. >        }
  30. >
  31. >        Nostream& operator << ( Nostream& (*funcPtr)(const char *msg)
  32. >) {
  33. >            return (*funcPtr)(msg);
  34. >        }
  35. >
  36. >        .... // some more functionality...
  37. >}
  38. >
  39. >int main()
  40. >{
  41. >        Nostream nout(cout.rdbuf());
  42. >
  43. >        nout << "TEST" << endl;
  44. >
  45. >        nout.header("blah");    --------- 1
  46. >        nout << header("blah"); --------- 2
  47. >}
  48. >--------------------------------------------------
  49. >
  50. > ....
  51. >"foo.C", line 38: Error: msg is not defined.    <<<--------!!!!
  52.  
  53. Right.  msg is not an argument of operator<<.  It is an argument of
  54. the type of function pointer that is being passed to operator<<,
  55. but that is a different matter.
  56.  
  57. And what in the world is:
  58.         nout.header("blah");
  59. Has header been defined as a method of Nostream?
  60.  
  61. As for
  62.         nout << header("blah");
  63. this is the same as
  64.     nout.operator<<(header("blah"))
  65. which is passing the *return value* of the (undefined)
  66. method/function header called with "blah".  Once you
  67. define "header", and get an idea of what it's return
  68. value is, then you can try this again...
  69.  
  70. john lilley
  71.  
  72.  
  73.  
  74.  
  75.