home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!wupost!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!eff!ibmpcug!pipex!demon!cix.compulink.co.uk!vadim
- Newsgroups: comp.lang.c++
- From: vadim@cix.compulink.co.uk (Vadim Lebedev)
- Subject: Re: Renew?
- Cc: vadim@cix.compulink.co.uk
- Reply-To: vadim@cix.compulink.co.uk
- Date: Sun, 26 Jul 1992 19:04:09 +0000
- Message-ID: <memo.542965@cix.compulink.co.uk>
- Sender: usenet@gate.demon.co.uk
- Lines: 54
-
- In-Reply-To: <23316@alice.att.com> ark@alice.att.com (Andrew Koenig)
-
- Well, here are my 2 bits on operator renew. How about following?:
-
- class Renew { };
-
- const Renew RENEW;
-
- class ObjWithRenew
- {
- protected:
- void virtual renewed(size_t) { }
- public:
- void *operator new(size_t s) { return (void *) new char[s]; }
- void *operator new(void *old, Renew , size_t newsize, size_t)
- {
- ObjWithRenew *p;
- p = (ObjWithRenew *)realloc(old, newsize);
- p->renewed(s); // We can do this because realloc copied
- // the vptr too
- return (void *)p;
- }
- };
-
- // Now we can write
-
-
- class A: public ObjWithRenew
- {
- void virtual renew(size_t) { /* whatever */ }
- public:
- A(int a, b);
- A(char *s);
-
- };
-
- void test()
- {
- A *a1 = new A(2, 4);
-
- .....
- size_t newSize = ....;
-
- A *a2 = new(a1, RENEW, newSize) A("abc");
-
- }
-
-
- -----------------------------------------------------------------------
- Vadim Lebedev | Kortex International
- vadim@cix.compulink.co.uk | 139-147 av. Paul-Vaillant Couturier
- | 93126 La Courneuve - CEDEX, France
-
-
-