home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16576 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  1.2 KB

  1. Path: sparky!uunet!destroyer!sol.ctr.columbia.edu!emory!emory!usenet
  2. From: sb@next.neuro.emory.edu (Stephen O. Berger)
  3. Newsgroups: comp.lang.c++
  4. Subject: Template classes and overloaded binary operators on differing types
  5. Date: 19 Nov 1992 18:38:44 GMT
  6. Organization: Emory University, Dept of Math and CS
  7. Lines: 29
  8. Message-ID: <1egmvkINNi35@emory.mathcs.emory.edu>
  9. Reply-To: sb@next.neuro.emory.edu
  10. NNTP-Posting-Host: next.neuro.emory.edu
  11.  
  12.  
  13.  
  14. Hi,
  15.  
  16.   Can someone please comment on the following problem and suggest the
  17. "best" way to solve it.
  18.  
  19.    Say I have a template class that implements a VECTOR type and binary
  20.  operators like addition and subtraction. All of the binary operators are  
  21. currently implemented as template friend functions which accept two  
  22. vectors of the same type. For example, I have this :
  23.  
  24.  
  25.   VECTOR<int> ivec1(3),ivec2(3),ivec3(3);  // 3 is vector size
  26.  
  27.   ivec3 = ivec1 + ivec2;   
  28.  
  29.   My question is, how can I extend this so that I can add vectors of  
  30. differing types ?  e.g.,
  31.  
  32.     VECTOR<int> ivec1(3);
  33.         VECTOR<double> dvec1(3),dvec2(3);
  34.  
  35.         dvec2 = ivec1 + dvec1;
  36.  
  37.  What is a good way to implement this ?
  38.  
  39.  
  40.  Steve Berger (sb@onripx.neuro.emory.edu)
  41.