home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!caen!kuhub.cc.ukans.edu!parsifal.umkc.edu!vax1.umkc.edu!kramasamy
- Newsgroups: comp.lang.c++
- Subject: Re: C++ Return Types
- Message-ID: <1992Jul21.112354.1@vax1.umkc.edu>
- From: kramasamy@vax1.umkc.edu
- Date: Tue, 21 Jul 1992 17:23:54 GMT
- Sender: root@parsifal.umkc.edu (Parsifal Administration)
- References: <BrMJyE.FBM@watserv1.waterloo.edu> <1992Jul19.152207.1@cstp.umkc.edu> <23240@alice.att.com>
- Organization: University of Missouri - Kansas City
- Lines: 60
-
- In article <23240@alice.att.com>, ark@alice.att.com (Andrew Koenig) writes:
- > In article <1992Jul19.152207.1@cstp.umkc.edu> pkailasam@cstp.umkc.edu writes:
- >
- >> bitmap &bitmap::operator |(const bitmap &bm)
- >> {
- >> bitmap *bm1 = new bitmap ;
- >>
- >> // Do the necessary operations in the bitmap pointer bm1
- >>
- >> return *bm1 ;
- >> }
- >
- > Thereby allocating a bitmap every time the function is called
- > and never freeing it. How about the obvious approach:
- >
- > bitmap operator| (const bitmap& x, const bitmap& y)
- > {
- > bitmap result;
- >
- > // build up the result in `result', then...
- >
- > return result;
- > }
- > --
- > --Andrew Koenig
- > ark@europa.att.com
-
- Consider the bitmap to be of the following class definition
-
- class bitmap
- {
- ...
-
- char *ptr ;
-
- public :
-
- bitmap()
- {
- ...
- ptr = new char[10] ;
- } ;
-
-
- ~bitmap()
- {
- delete [] ptr ;
- } ;
- } ;
-
- If we adopt the second solution for the above class definition we run
- into problems of deallocating 'ptr' thro' destructor and the calling routine will
- get a garbage bitmap. How can we return for such cases?
-
-
- -karthik
-
- karthik@vax1.umkc.edu
-
-
-