home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18136 < prev    next >
Encoding:
Text File  |  1992-12-17  |  1.4 KB  |  40 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!caen!spool.mu.edu!umn.edu!csus.edu!borland.com!pete
  3. From: pete@borland.com (Pete Becker)
  4. Subject: Re: Matrix Addition  Was Re: Complex Addition.
  5. Message-ID: <1992Dec17.184348.217@borland.com>
  6. Originator: pete@genghis.borland.com
  7. Keywords: operator, memory leak
  8. Sender: news@borland.com (News Admin)
  9. Organization: Borland International
  10. References: <1992Dec11.170849.18525@rs6000.bham.ac.uk> <1992Dec11.232954.7071@borland.com> <36223@sophia.inria.fr>
  11. Date: Thu, 17 Dec 1992 18:43:48 GMT
  12. Lines: 26
  13.  
  14. In article <36223@sophia.inria.fr> gchow@hawai.inria.fr (Gloria Chow) writes:
  15. >
  16. >How about if the structure is a bit more complex, especially one with
  17. >dynamically allocated memory.  I tried the following (I appologize if it's
  18. >syntactically incorrect, I no longer have the version which I actually tried.
  19. >This one is just from memory):
  20. >
  21. >class MATRIX
  22. >{
  23. >protected:
  24. >    double      **entry;
  25. >    int         nrows, ncols;
  26. >public:
  27. >    MATRIX( int num_rows, int num_cols );
  28. >    MATRIX& operator=( const MATRIX& equivalent );
  29. >    MATRIX& operator+( const MATRIX& addend );
  30. >};
  31. >
  32.  
  33.     Add a copy constructor.  If you don't supply one, the compiler will
  34. provide one for you, and it often won't do what you want it to do.  In
  35. general, there are three member functions that should probably all be present
  36. if any one of them is: assignment operator, copy constructor, and destructor.
  37.     -- Pete
  38.  
  39.  
  40.