home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18945 < prev    next >
Encoding:
Text File  |  1993-01-11  |  1.5 KB  |  52 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!debbie!ennisj
  3. From: ennisj@tt.com (Jay Ennis)
  4. Subject: Base Class Pointers to Derived Class Objects. Is this Possible?
  5. Message-ID: <1993Jan11.154339.2969@debbie>
  6. Sender: news@debbie
  7. Nntp-Posting-Host: debbie
  8. Organization: Telecommunications Techniques Corporation, Germantown MD
  9. Date: Mon, 11 Jan 1993 15:43:39 GMT
  10. Lines: 40
  11.  
  12. I am trying to create an array of base class member pointers to a group of
  13. derived class objects.  It strikes me as a perfectly legal thing to do.
  14.  
  15. When compiling the attached sample, Borland C++ 3.1 returns the error message
  16.     "Cannot convert 'DERIVED_CLASS OBJECT_DB::*' to 'BASE_CLASS OBJECT_DB::*'"
  17. indicating to me that iheritance of the base class isn't possible in this case.
  18.  
  19. Does anyone have any suggestions, ideas or workarounds?  Is this a bug?
  20. Any assistance is most appreciated.  Please reply by e-mail.
  21.  
  22. *********************** Sample *****************************
  23.  
  24. class BASE_CLASS {
  25.    public:
  26.        virtual void Function(void) = 0;
  27. };
  28.  
  29. class DERIVED_CLASS: public BASE_CLASS {
  30.     public:
  31.     void Function(void);
  32. };
  33.  
  34. void DERIVED_CLASS::Function(void) {}
  35.  
  36. struct OBJECT_DB {
  37.     DERIVED_CLASS    Item1;
  38. };
  39.  
  40. BASE_CLASS OBJECT_DB::*BC_Array[] = {
  41.     &OBJECT_DB::Item1
  42.     };
  43.  
  44. void main(void) {
  45.     OBJECT_DB    ObjectDB;
  46.     ObjectDB.*BC_Array[0].Function();
  47. }
  48. -- 
  49. Jay Ennis 
  50. ennisj@tt.com               "The sea is your wife, your ship your mistress,
  51.                                   and the land a treacherous whore"
  52.