home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!batcomputer!cornell!rochester!rit!cci632!dwr
- From: dwr@cci632.cci.com (Donald W. Rouse II)
- Subject: Re: Operator "new" - how to catch array-allocation?
- Message-ID: <1992Dec15.172622.14291@cci632.cci.com>
- Organization: [Computer Consoles, Inc., Rochester, NY
- References: <1992Dec14.143339.26314@daimi.aau.dk>
- Date: Tue, 15 Dec 1992 17:26:22 GMT
- Lines: 39
-
- In article <1992Dec14.143339.26314@daimi.aau.dk> sabroe@daimi.aau.dk (Morten Sabroe Mortensen) writes:
- >
- >As you know, it's possible to attach a special 'new' operator on a
- >specific class, -something like
- >
- >...
- >
- >class A
- >{
- > ...
- >
- >public:
- > void* operator new(size_t s);
- >}
- >
- >...
- >
- >So, well, -when doing something like
- >
- >A* a=new A;
- >
- >the new 'new' for my class A is used, but when doing something like
- >
- >A* a=new A[25];
- >
- >the global new operator is used, it seems! Can it be true, it should
- >work like this? Until I tried, I thought, A's 'new' would just get a bigger
- >argument - but maybe there is a very good reason, it works like this?
- >Please tell me about it! No way to catch array-allocation for a class?
- >Same question goes for 'delete'. Comments and explanations greatly
- >appreciated!
-
- It's because an array of A is not type "A"; it's type "array of A",
- which is something entirely different.
- BS explains this somewhere in his book.
- It would be nice to be able to easily specify a "new" operator
- for things like "array of A", "pointer to A", etc.
- (I realize you can do this with a wrapper class, but it's not easy.
- Maybe someone out there has templates for this?)
-