home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!brunix!brunix!sdm
- From: sdm@cs.brown.edu (Scott Meyers)
- Subject: Re: Make a deep copy!
- Message-ID: <1992Dec19.154329.25789@cs.brown.edu>
- Sender: news@cs.brown.edu
- Organization: Brown University Department of Computer Science
- References: <kwong.724744711@morgan>
- Date: Sat, 19 Dec 1992 15:43:29 GMT
- Lines: 21
-
- In article <kwong.724744711@morgan> kwong@morgan.ucs.mun.ca (KAI S. WONG ^.^) writes:
- | How about if the structure is a bit more complex, especially one with
- | dynamically allocated memory. I tried the following (I appologize if it's
- | syntactically incorrect, I no longer have the version which I actually tried.
- | This one is just from memory):
- |
- | class MATRIX
- | {
- ...
- | MATRIX& operator+( const MATRIX& addend );
- | };
-
- Your problem is that operator+ can't return a reference. Well, it can, but
- if it does, it won't work correctly, as you have discovered. The general
- problem is that you're returning a reference to an object that is going out
- of scope. For details, see "Effective C++," pp. 82-84.
-
- Scott
-
- -------------------------------------------------------------------------------
- What do you say to a convicted felon in Providence? "Hello, Mr. Mayor."
-