home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / g / help / 1695 < prev    next >
Encoding:
Text File  |  1993-01-23  |  1.4 KB  |  57 lines

  1. Path: sparky!uunet!stanford.edu!rock!concert!duke!mcduff.uncg.edu!brinerj
  2. From: brinerj@mcduff.uncg.edu (Jack V. Briner Jr.)
  3. Newsgroups: gnu.g++.help
  4. Subject: new operator with multiple arguments (gcc-2.2.2)
  5. Message-ID: <22983@duke.cs.duke.edu>
  6. Date: 22 Jan 93 21:24:50 GMT
  7. Sender: news@duke.cs.duke.edu
  8. Reply-To: brinerj@mcduff.uncg.edu (Jack V. Briner Jr.)
  9. Organization: UNCG Department of Mathematics
  10. Lines: 44
  11. Nntp-Posting-Host: mcduff.uncg.edu
  12.  
  13. I would like to pass arguments to the new operator (to select memory from
  14. different segments).  g++ does not seem to have this implemented under gcc-2.2.2.  Here is some example code that compiles fine under cfront.  Does a
  15. newer release accept this code?
  16.  
  17. Thanks,
  18. Jack
  19.  
  20.  
  21. #include <iostream.h>
  22. #include <stddef.h>
  23. class t {
  24. public:
  25.         int i; 
  26.  
  27.         // ok
  28.     void *operator new(size_t sz) {
  29.              t *n;
  30.              n = (t *)new char[sz];
  31.              return n;
  32.              }
  33.  
  34.         // not ok when used in main
  35.     void *operator new(size_t sz,int i) {
  36.              t *n;
  37.              n = (t *)new char[sz];
  38.              n->i = i;  // not what I am really doing in my application
  39.              return n;
  40.              }
  41.  
  42. };
  43.  
  44. main () {
  45.    
  46.    t *a = new t; // ok
  47.    t *b = new(5) t; // not ok,  parse error before `5'
  48. }
  49.   
  50.  
  51.  
  52. --
  53. Jack V. Briner,Jr.        Department of Mathematics
  54. brinerj@mcduff.uncg.edu        University of North Carolina at Greensboro
  55. brinerj@steffi.uncg.edu        Greensboro, NC 27412
  56. brinerj@UNCG.Bitnet        (919)334-5836
  57.