From: Shue-Cheng CHEN 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 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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