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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsk!swk7
  3. From: swk7@cbnewsk.cb.att.com (steven.w.koenig)
  4. Subject: Undefined new and delete
  5. Organization: AT&T
  6. Date: Mon, 21 Dec 1992 16:22:41 GMT
  7. Message-ID: <1992Dec21.162241.12012@cbnewsk.cb.att.com>
  8. Lines: 48
  9.  
  10. If one wanted to insure that no objects of a given type were ever created
  11. on the heap, it seems logical that one should be able to declare the
  12. new and delete operators as private but not define them. cfront 2.1
  13. only seems to support this if the constructors are inline. The following
  14. example works if A and ~A are inline, but gives the following error if 
  15. A and ~A are not inline. 
  16.  
  17. Questions:
  18. 1. Are declared but undefined new and delete operators legal C++ ?
  19. 2. If so, is this a cfront bug.
  20.  
  21.  
  22. #include <stddef.h>
  23.  
  24. class A
  25. {
  26. public: // Functions
  27.  
  28.         A() {a=0;}
  29.         ~A() {a=0;}
  30.  
  31. private: // Data
  32.         int a;
  33.  
  34. private: // Functions (undefined)
  35.         void* operator new(size_t);
  36.         void operator delete(void*,size_t);
  37. };
  38.  
  39. main()
  40. {
  41.         A aa;
  42.  
  43.         return 0;
  44. }
  45.  
  46.  
  47. // CC +d means don't expand inlines
  48.  
  49. CC  +d bug.c:
  50. cc  -Wl,-L/ut2f/utssgs/sgen1.0/lib/C++/2.1/lib   bug.c -lC
  51. + /etc/preroot /ccs/native /bin/cc -Wl,-L/ut2f/utssgs/sgen1.0/lib/C++/2.1/lib /C
  52. undefined               first referenced
  53.  symbol                     in file
  54. A::operator new(unsigned int)   /CCtmp/CC.10864/bug.o
  55. A::operator delete(void*,unsigned int) /CCtmp/CC.10864/bug.o
  56. ld fatal: Symbol referencing errors. No output written to a.out
  57.  
  58.