cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1999/01/21/00:07:32

From: Shue-Cheng CHEN <scchen AT ohriki DOT t DOT u-tokyo DOT ac DOT jp>
Newsgroups: comp.lang.c++,comp.os.msdos.djgpp
Subject: How to implement "They are all Vectors, but different realities?"
Date: 21 Jan 1999 02:05:28 GMT
Organization: Dept of Civil Engineering, the University of Tokyo
Lines: 29
Message-ID: <36A68B87.FFBA110C@ohriki.t.u-tokyo.ac.jp>
NNTP-Posting-Host: chen.ohriki.t.u-tokyo.ac.jp
Mime-Version: 1.0
X-Mailer: Mozilla 4.5 [en] (Win95; I)
X-Accept-Language: en
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi!

     We know "Force" and "Velocity" are both "Vectors" in mathematics, so
I defined them to own all behaviors and data of Vector (has been defined),
without duplicating the code, as follows,

        class Force    : public Vector {...};
        class Velocity : public Vector {...};

Therefore, the operators of Vector, for example, operator+(Vector&, Vector&)
can be used for Force and Velocity, like

        Force    + Force      // Ok
        Velocity + Velocity   // Ok

    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?

    Thanks a lot!

Best Regards,

Shue-Cheng CHEN

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019