home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18209 < prev    next >
Encoding:
Text File  |  1992-12-21  |  3.0 KB  |  47 lines

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!swrinde!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
  2. From: friedman@hp-and.an.hp.com (joel friedman)
  3. Newsgroups: comp.lang.c++
  4. Subject: Any inheritance experts out there
  5. Keywords: Inheritance, virtual functions
  6. Message-ID: <4019@hpwala.wal.hp.com>
  7. Date: 18 Dec 92 14:44:03 GMT
  8. Sender: netnews@hpwala.wal.hp.com
  9. Organization: Hewlett-Packard Company
  10. Lines: 35
  11.  
  12. Hello all,
  13.  
  14. 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!!
  15.  
  16. Down to business.  I need some assistance designing my class hierarchies for the following situation:
  17.  
  18. 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:
  19.  
  20. template <class T> class core_functions
  21. {
  22. public:
  23.    T Read cell(int address);
  24.    void Write_cell(int address, T data);
  25. };
  26.  
  27.  
  28. 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).
  29.  
  30. 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.
  31.  
  32. 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.
  33.  
  34. 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,
  35. which is a requirement.
  36.  
  37. Any Ideas?? Thanks in advance.
  38. Joel
  39. -- 
  40. __________________________________________________________________________
  41. Joel Friedman           friedman@hp-and.an.hp.com           (508) 681-2709
  42.  
  43.  ///  /_ _  \\\   H E W L E T T          Imaging Systems Division
  44. (((  / //_/  )))                         3000 Minuteman Road
  45.  \\\   /    ///   P A C K A R D          Andover, Massachusetts 01810-1087
  46. __________________________________________________________________________
  47.