home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsk!swk7
- From: swk7@cbnewsk.cb.att.com (steven.w.koenig)
- Subject: Undefined new and delete
- Organization: AT&T
- Date: Mon, 21 Dec 1992 16:22:41 GMT
- Message-ID: <1992Dec21.162241.12012@cbnewsk.cb.att.com>
- Lines: 48
-
- If one wanted to insure that no objects of a given type were ever created
- on the heap, it seems logical that one should be able to declare the
- new and delete operators as private but not define them. cfront 2.1
- only seems to support this if the constructors are inline. The following
- example works if A and ~A are inline, but gives the following error if
- A and ~A are not inline.
-
- Questions:
- 1. Are declared but undefined new and delete operators legal C++ ?
- 2. If so, is this a cfront bug.
-
-
- #include <stddef.h>
-
- class A
- {
- public: // Functions
-
- A() {a=0;}
- ~A() {a=0;}
-
- private: // Data
- int a;
-
- private: // Functions (undefined)
- void* operator new(size_t);
- void operator delete(void*,size_t);
- };
-
- main()
- {
- A aa;
-
- return 0;
- }
-
-
- // CC +d means don't expand inlines
-
- CC +d bug.c:
- cc -Wl,-L/ut2f/utssgs/sgen1.0/lib/C++/2.1/lib bug.c -lC
- + /etc/preroot /ccs/native /bin/cc -Wl,-L/ut2f/utssgs/sgen1.0/lib/C++/2.1/lib /C
- undefined first referenced
- symbol in file
- A::operator new(unsigned int) /CCtmp/CC.10864/bug.o
- A::operator delete(void*,unsigned int) /CCtmp/CC.10864/bug.o
- ld fatal: Symbol referencing errors. No output written to a.out
-
-