home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!psinntp!ncrlnk!ncr-mpd!Eric.Price
- From: Eric.Price@FtCollins.NCR.com (Eric.Price)
- Newsgroups: comp.lang.c++
- Subject: Re: error in Stroustrup text (?)
- Message-ID: <ERIC.PRICE.92Aug12131243@sousa.FtCollins.NCR.com>
- Date: 12 Aug 92 12:12:43 GMT
- References: <46960007@hpscit.sc.hp.com>
- Sender: uucp@ncr-mpd.FtCollins.NCR.COM
- Reply-To: Eric.Price@FtCollinsCO.NCR.com
- Organization: NCR Microelectronics, Ft. Collins, CO
- Lines: 33
- In-reply-to: weeks@hpscit.sc.hp.com's message of 11 Aug 92 19:00:10 GMT
-
- >>>>> On 11 Aug 92 19:00:10 GMT, weeks@hpscit.sc.hp.com (Greg Weeks) said:
-
- Greg> Someone please correct me if I'm mistaken, but the following text from pg
- Greg> 216 of Stroustrup's 2nd edition C++ text seems to be wrong:
-
- Greg> If you want to supply an allocator/dealocator pair that works correctly
- Greg> for derived classes, you must either supply a virtual destructor in the
- Greg> base class or refrain from using the size_t argument in the
- Greg> deallocator.
-
- I suspect Dr Stroustrup's unstated assumption is that a deallocator
- which does not use the size_t argument accesses the size of the
- allocated memory from a location where the allocator has secretly
- squirreled it away. (That information might include the initially
- allocated address, if polymorphic MI is supported by the allocator.)
-
- Greg> _Whenever_ a derived class object may be deleted through a pointer to base
- Greg> object, a virtual destructor is required. It does not suffice to refrain
- Greg> from using the size_t argument in the deallocator. The reason is that
- Greg> `delete' needs to know both the size _and_ the location of the thing to be
- Greg> deleted; and the location of the derived object may differ from the
- Greg> location of the base object. (That is, it may be that (void*)pd is
- Greg> different from (void*)pb.)
-
- The section you reference does not discuss multiple inheritance. Given
- single inheritance, (void*)pd would equal (void*)pb.
-
- -Eric
- --
- Eric Price, Software Architect, Computer Aided Design
- NCR Microelectronic Products Division
- 2001 Danfield Court; Ft. Collins, CO 80525
- (303) 223-5100 x471; FAX: 226-9556; EMAIL: Eric.Price@FtCollinsCO.NCR.COM
-