home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!dtix!darwin.sura.net!uvaarpa!murdoch!virginia.edu!gs4t
- From: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Newsgroups: comp.lang.c++
- Subject: Re: C++ Return Types
- Message-ID: <1992Jul21.215453.8138@murdoch.acc.Virginia.EDU>
- Date: 21 Jul 92 21:54:53 GMT
- References: <BrMJyE.FBM@watserv1.waterloo.edu> <1992Jul19.152207.1@cstp.umkc.edu> <23240@alice.att.com> <1992Jul21.112354.1@vax1.umkc.edu>
- Sender: usenet@murdoch.acc.Virginia.EDU
- Reply-To: gs4t@virginia.edu (Gnanasekaran Swaminathan)
- Organization: University of Virginia
- Lines: 41
-
- kramasamy@vax1.umkc.edu writes:
- >ark@alice.att.com (Andrew Koenig) writes:
- >> bitmap operator| (const bitmap& x, const bitmap& y)
- >> {
- >> bitmap result;
- >>
- >> // build up the result in `result', then...
- >>
- >> return result;
- >> }
- >
- > 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?
-
- The solution, in this case, is a proper copy constructor.
- That is, you need
-
- bitmap::bitmap(const bitmap& b)
- : ptr(new char[10])
- {
- strcpy(ptr, b.ptr);
- }
-
- -Sekar
-