home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / gnu / g / help / 1150 < prev    next >
Encoding:
Text File  |  1992-08-23  |  1.6 KB  |  43 lines

  1. Newsgroups: gnu.g++.help
  2. Path: sparky!uunet!usc!sol.ctr.columbia.edu!caen!nic.umass.edu!cis.umassd.edu!ulowell!cs.ulowell.edu!jrichard
  3. From: jrichard@cs.ulowell.edu (John 'MacGyver' Richardson)
  4. Subject: help with operator new (can you overload it?)
  5. Message-ID: <1992Aug23.181826.28513@ulowell.ulowell.edu>
  6. Sender: usenet@ulowell.ulowell.edu (News manager - ulowell)
  7. Organization: University of Massachusetts at Lowell Computer Science
  8. Date: Sun, 23 Aug 1992 18:18:26 GMT
  9. Lines: 32
  10.  
  11.  
  12. I'm having some trouble trying to overload the new operator with g++2.2.2.
  13. Is there some switch to turn on overloading for the new operator? 
  14.  
  15. The following example program doesn't complile under g++ but does under 
  16. cfront3.0.  Can someone tell me what's up here?  Email if possible. 
  17.                 Thanks.
  18.  
  19. -------------------
  20. #include <stdio.h>
  21. #include <string.h>
  22.  
  23. inline void *operator new(size_t, void *addr) { 
  24.     return addr;
  25. }
  26.  
  27. int main() {
  28.     char buffer[1000];
  29.     strcpy(buffer, "Hello Gnu World\n");          // I realize this is weird
  30.                                                   // but its just an example.
  31.     char *s = new (buffer) char;                  // g++ gives error here.
  32.     printf("buffer is %s", buffer);               
  33. }
  34.  
  35.  
  36. John 'MacGyver' Richardson |"sun dogs fire on the horizon        \ \   \
  37. jrichard@cs.ulowell.edu    | meteor rain stars across the night   * *   \   /\
  38. jrichard@duck.ulowell.edu  | ...the spark still flies                /\  * /  \
  39.                            | reflected in another pair of eyes." /\ /  \/\/
  40.                                                            ------  \   / / 
  41.  
  42.  
  43.