home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18017 < prev    next >
Encoding:
Text File  |  1992-12-15  |  1.6 KB  |  50 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!batcomputer!cornell!rochester!rit!cci632!dwr
  3. From: dwr@cci632.cci.com (Donald W. Rouse II)
  4. Subject: Re: Operator "new" - how to catch array-allocation?
  5. Message-ID: <1992Dec15.172622.14291@cci632.cci.com>
  6. Organization: [Computer Consoles, Inc., Rochester, NY
  7. References: <1992Dec14.143339.26314@daimi.aau.dk>
  8. Date: Tue, 15 Dec 1992 17:26:22 GMT
  9. Lines: 39
  10.  
  11. In article <1992Dec14.143339.26314@daimi.aau.dk> sabroe@daimi.aau.dk (Morten Sabroe Mortensen) writes:
  12. >
  13. >As you know, it's possible to attach a special 'new' operator on a
  14. >specific class, -something like
  15. >
  16. >...
  17. >
  18. >class A
  19. >{
  20. >  ...
  21. >
  22. >public:
  23. >  void* operator new(size_t s);
  24. >}
  25. >
  26. >...
  27. >
  28. >So, well, -when doing something like
  29. >
  30. >A* a=new A;
  31. >
  32. >the new 'new' for my class A is used, but when doing something like
  33. >
  34. >A* a=new A[25];
  35. >
  36. >the global new operator is used, it seems! Can it be true, it should
  37. >work like this? Until I tried, I thought, A's 'new' would just get a bigger
  38. >argument - but maybe there is a very good reason, it works like this?
  39. >Please tell me about it! No way to catch array-allocation for a class? 
  40. >Same question goes for 'delete'. Comments and explanations greatly
  41. >appreciated!
  42.  
  43. It's because an array of A is not type "A"; it's type "array of A",
  44. which is something entirely different.
  45. BS explains this somewhere in his book.
  46. It would be nice to be able to easily specify a "new" operator
  47. for things like "array of A", "pointer to A", etc.
  48. (I realize you can do this with a wrapper class, but it's not easy.
  49. Maybe someone out there has templates for this?)
  50.