home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!debbie!ennisj
- From: ennisj@tt.com (Jay Ennis)
- Subject: Base Class Pointers to Derived Class Objects. Is this Possible?
- Message-ID: <1993Jan11.154339.2969@debbie>
- Sender: news@debbie
- Nntp-Posting-Host: debbie
- Organization: Telecommunications Techniques Corporation, Germantown MD
- Date: Mon, 11 Jan 1993 15:43:39 GMT
- Lines: 40
-
- I am trying to create an array of base class member pointers to a group of
- derived class objects. It strikes me as a perfectly legal thing to do.
-
- When compiling the attached sample, Borland C++ 3.1 returns the error message
- "Cannot convert 'DERIVED_CLASS OBJECT_DB::*' to 'BASE_CLASS OBJECT_DB::*'"
- indicating to me that iheritance of the base class isn't possible in this case.
-
- Does anyone have any suggestions, ideas or workarounds? Is this a bug?
- Any assistance is most appreciated. Please reply by e-mail.
-
- *********************** Sample *****************************
-
- class BASE_CLASS {
- public:
- virtual void Function(void) = 0;
- };
-
- class DERIVED_CLASS: public BASE_CLASS {
- public:
- void Function(void);
- };
-
- void DERIVED_CLASS::Function(void) {}
-
- struct OBJECT_DB {
- DERIVED_CLASS Item1;
- };
-
- BASE_CLASS OBJECT_DB::*BC_Array[] = {
- &OBJECT_DB::Item1
- };
-
- void main(void) {
- OBJECT_DB ObjectDB;
- ObjectDB.*BC_Array[0].Function();
- }
- --
- Jay Ennis
- ennisj@tt.com "The sea is your wife, your ship your mistress,
- and the land a treacherous whore"
-