home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18557 < prev    next >
Encoding:
Text File  |  1992-12-30  |  1.1 KB  |  45 lines

  1. Path: sparky!uunet!cs.utexas.edu!devnull!seiko.mpd.tandem.com!rjf
  2. From: rjf@seiko.mpd.tandem.com (Russell Fleming)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Simulate "Pointer to char" by an array
  5. Message-ID: <3223@devnull.mpd.tandem.com>
  6. Date: 30 Dec 92 19:53:47 GMT
  7. References: <1992Dec30.172241.11378@dcs.warwick.ac.uk>
  8. Sender: news@devnull.mpd.tandem.com
  9. Lines: 34
  10.  
  11. In article <1992Dec30.172241.11378@dcs.warwick.ac.uk>,
  12. cmchan@dcs.warwick.ac.uk (C M Chan) writes:
  13. >  
  14. > How can I simulate "pointer to char" by an array in a class whose size
  15. will be \
  16. > delayed to be
  17. > defined at run time?
  18. >  
  19. > For example, [... DELETED ...]
  20.  
  21. If I understand your question correctly, you can add a char* operator to
  22. the class which will return the type of pointer you are looking for. 
  23. For example:
  24.  
  25. class X {
  26. private:
  27.     char str[...];
  28. public:
  29.     X(void);
  30.     ~X(void);
  31.     operator char* (void) { return str; }
  32. };
  33.  
  34. main ()
  35. {
  36.     X x;
  37.     char s[...];
  38.     strcpy (s, (char *) x);
  39. }
  40.  
  41. =================================================================
  42. Rusty Fleming, Software Consultant @ Tandem Computers Inc.
  43. email: rjf@mpd.tandem.com            Austin, Texas
  44. voice: (512) 244 - 8390              USA
  45.