home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13371 < prev    next >
Encoding:
Internet Message Format  |  1992-09-08  |  1.6 KB

  1. Path: sparky!uunet!snorkelwacker.mit.edu!ai-lab!life.ai.mit.edu!tmb
  2. From: tmb@arolla.idiap.ch (Thomas M. Breuel)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: defining cast operators outside classes
  5. Message-ID: <TMB.92Sep7203926@arolla.idiap.ch>
  6. Date: 8 Sep 92 00:39:26 GMT
  7. References: <TMB.92Sep7162324@arolla.idiap.ch>
  8.     <1992Sep7.154125.28472@murdoch.acc.Virginia.EDU>
  9. Sender: news@ai.mit.edu
  10. Reply-To: tmb@idiap.ch
  11. Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
  12.     Perceptive)
  13. Lines: 26
  14. In-reply-to: gs4t@virginia.edu's message of 7 Sep 92 15:41:25 GMT
  15.  
  16. In article <1992Sep7.154125.28472@murdoch.acc.Virginia.EDU> gs4t@virginia.edu (Gnanasekaran Swaminathan) writes:
  17.  
  18.    tmb@arolla.idiap.ch (Thomas M. Breuel) writes:
  19.    : Apparently, it is impossible to define a conversion operator for a
  20.    : class without making the conversion operator a member function.
  21.    : 
  22.    : It would be very useful to be able to define something like the
  23.    : following without having to modify either class MyMatrix or class
  24.    : TheirMatrix:
  25.    : 
  26.    :     operator MyMatrix(TheirMatrix &m) {
  27.    :         ...
  28.    :     }
  29.    : 
  30.    : Why was this seemingly arbitrary restriction made? Can it be
  31.    : eliminated in the next version of C++?
  32.  
  33.    You can achieve what you want by providing a constructor in your
  34.    MyMatrix class that takes a reference to TheirMatrix as its
  35.    argument. For example,
  36.  
  37. Please read my posting carefully: I don't want to modify either
  38. MyMatrix or TheirMatrix. Perhaps I should have chosen type names of
  39. "TheirMatrix" and "SomeOtherMatrix" to make this even more obvious.
  40.  
  41.                     Thomas.
  42.