home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!agate!stanford.edu!unix!hplabs!hp-cv!hp-pcd!news1.boi.hp.com!cupnews0.cup.hp.com!hpscit.sc.hp.com!hplextra!hpcss01!hpwala!friedman
- From: friedman@hp-and.an.hp.com (joel friedman)
- Newsgroups: comp.lang.c++
- Subject: Any inheritance experts out there? reprise
- Keywords: inheritance, virtual
- Message-ID: <4021@hpwala.wal.hp.com>
- Date: 18 Dec 92 16:17:18 GMT
- Sender: netnews@hpwala.wal.hp.com
- Organization: Hewlett-Packard Company
- Lines: 57
-
- Hello all,
-
- I'd like to start off by thanking the many of you who provided me info about
- the ARM. I now have Stroustrup 2nd edition and it's just what I needed. The
- book I originally had was Stroustrup 1st edition, not a book by Dijikstra. My
- apologies for the mass confusion this caused!!
-
- Down to business. I need some assistance designing my class hierarchies for
- the following situation:
-
- I am writing device drivers for external memory devices. I currently have to
- support two types devices (say A and B), but that number could grow. The
- functions each device must support are common, but the implementations used to
- provide them are quite different for each. The type T below can be a char xor
- a short. The following template class defines these core functions:
-
- template <class T> class core_functions
- {
- public:
- T Read cell(int address);
- void Write_cell(int address, T data);
- };
-
-
- I want to design the hierarchy so I can easily add device C, D, E etc. Here's
- the catch. How can I do this so that the application programs only need to see
- the core_function class declaration; not the derived class declarations for A
- or B. I need to enhance the core_functions class so that the user can call a
- core_functions function, and it will be directed to the implementation in the
- proper derived class (A or B).
-
- If I derive A or B from core_functions, then the application must declare
- objects of type A or B, thus they will need to have access to the derived class
- declarations.
-
- If I use A or B as a base class, then there have to be different derived
- core_functions classes; one derived from A, the other from B. This prevents
- the user from seeing the declarations for A and B, but doesn't seem very
- elegant. I want to have only 1 core_functions class.
-
- I tried making the core_functions functions virtual. That let me call
- core_functions functions, redirecting them to the implementations in A and B.
- This didn't prevent the application from needing the A and B class
- declarations, which is a requirement.
-
- Any Ideas?? Thanks in advance.
- Joel
- --
- __________________________________________________________________________
- Joel Friedman friedman@hp-and.an.hp.com (508) 681-2709
-
- /// /_ _ \\\ H E W L E T T Imaging Systems Division
- ((( / //_/ ))) 3000 Minuteman Road
- \\\ / /// P A C K A R D Andover, Massachusetts 01810-1087
-
- #include <standard_disclaimer.h>
- __________________________________________________________________________
-