| delorie.com/archives/browse.cgi | search |
| Message-ID: | <36A6E9A6.C8FF45CE@eik.bme.hu> |
| Date: | Thu, 21 Jan 1999 09:47:35 +0100 |
| From: | "Dr. =?iso-8859-1?Q?Andr=E1s=20S=F3lyom?=" <solyom AT eik DOT bme DOT hu> |
| Organization: | TU Budapest |
| X-Mailer: | Mozilla 4.5 [en] (Win98; I) |
| X-Accept-Language: | en,hu |
| MIME-Version: | 1.0 |
| To: | djgpp AT delorie DOT com, Shue-Cheng CHEN <scchen AT ohriki DOT t DOT u-tokyo DOT ac DOT jp> |
| Subject: | Re: How to implement "They are all Vectors, but different realities?" |
| References: | <36A68B87 DOT FFBA110C AT ohriki DOT t DOT u-tokyo DOT ac DOT jp> |
| Reply-To: | djgpp AT delorie DOT com |
Shue-Cheng CHEN wrote:
>
...
> But "Force" and "Velocity" are different physical realities, so
>
> Force + Velocity // Wrong
>
> I would like to deploit the common implementation of them to avoid
> duplicating their code, but how should I do to prevent from Force +
> Vector meaningless operation?
I think this can solve your problem:
put a type variable into Vector whose value differ for Force and Velocity
and check this variable in operator+.
or perhaps this more complicated solution is also working:
Create a base class Vector and and separate derived classes for Force and
Velocity. These can use the same method for addition inherited from Vector, but
accept only the corresponding quantities.
Andras
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |