🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #2506

Re: Implicit operation relationships

#2506
From: John Barton
Date: Fri, 10 Nov 1995 19:16
36 lines
2076 bytes
In article <47qnbu$f48@oznet03.ozemail.com.au>, John Max Skaller <maxtal@suphys.physics.su.oz.au> writes:
|> jjb@watson.ibm.com (John Barton) wrote:
|> >In article <47dn87$a17@sunsystem5.informatik.tu-muenchen.de>,
|> >|> You can extend this idea:
|> >|>
|> >|> template<class T> T  operator- (T&a, T&b) { return a + (-b); }
|> >|> template<class T> T  operator- (T&a)      { return 0 - a; }
|> >|> template<class T> T& operator+ (T&a)      { return a; }
|> >|> template<class T> T& operator++(T&a)      { return a += 1; }
|> >|> template<class T> T& operator++(T&a,int)  { return ++a; }
|> >
|> >This will not work: it prevent you from writing any templates
|> >for these operators over types that do not have "1" or "0"
|> >or that need a definition other than the one above.
|>
|> How does it prevent it? [Quote WP ??]

template<class T>
Matrix<T> operator-(Matrix<T>& rhs) { /* doesn't matter what I code here */ }

The global operator-(T&) will always win over any more
specific template like the one above.  Unless the standard has
changed here as well.

--
John.

John J. Barton        jjb@watson.ibm.com            (914)784-6645
	<http://www.research.ibm.com/xw-SoftwareTechnology>
H1-C13 IBM Watson Research Center P.O. Box 704 Hawthorne NY 10598

---
[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID: <47vjou$i04@watnews2.watson.ibm.com>
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
References: <MATT.95Aug24221328@Austern> <46vaga$dng@marina.cinenet.net> <47dn87$a17@sunsystem5.informatik.tu-muenchen.de> <47l76s$qu1@watnews2.watson.ibm.com> <47qnbu$f48@oznet03.ozemail.com.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt
From: jjb@watson.ibm.com (John Barton)
Newsgroups: comp.std.c++
Subject: Re: Implicit operation relationships
Date: 10 Nov 1995 19:16:40 GMT
Organization: IBM T.J. Watson Research Center
Approved: matt@physics2.Berkeley.EDU (Matt Austern)
Message-ID: <47vjou$i04@watnews2.watson.ibm.com>
References: <MATT.95Aug24221328@Austern> <46vaga$dng@marina.cinenet.net> <47dn87$a17@sunsystem5.informatik.tu-muenchen.de> <47l76s$qu1@watnews2.watson.ibm.com> <47qnbu$f48@oznet03.ozemail.com.au>
NNTP-Posting-Host: physics2.berkeley.edu