home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!destroyer!sol.ctr.columbia.edu!emory!emory!usenet
- From: sb@next.neuro.emory.edu (Stephen O. Berger)
- Newsgroups: comp.lang.c++
- Subject: Template classes and overloaded binary operators on differing types
- Date: 19 Nov 1992 18:38:44 GMT
- Organization: Emory University, Dept of Math and CS
- Lines: 29
- Message-ID: <1egmvkINNi35@emory.mathcs.emory.edu>
- Reply-To: sb@next.neuro.emory.edu
- NNTP-Posting-Host: next.neuro.emory.edu
-
-
-
- Hi,
-
- Can someone please comment on the following problem and suggest the
- "best" way to solve it.
-
- Say I have a template class that implements a VECTOR type and binary
- operators like addition and subtraction. All of the binary operators are
- currently implemented as template friend functions which accept two
- vectors of the same type. For example, I have this :
-
-
- VECTOR<int> ivec1(3),ivec2(3),ivec3(3); // 3 is vector size
-
- ivec3 = ivec1 + ivec2;
-
- My question is, how can I extend this so that I can add vectors of
- differing types ? e.g.,
-
- VECTOR<int> ivec1(3);
- VECTOR<double> dvec1(3),dvec2(3);
-
- dvec2 = ivec1 + dvec1;
-
- What is a good way to implement this ?
-
-
- Steve Berger (sb@onripx.neuro.emory.edu)
-