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