home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!inews.Intel.COM!td2cad!dmarer
- From: dmarer@td2cad.intel.com (Dennis Marer)
- Newsgroups: comp.object
- Subject: Implementation of multiple inheritance?
- Keywords: multiple inheritance
- Message-ID: <BzDnvq.H86@inews.Intel.COM>
- Date: 17 Dec 92 00:26:13 GMT
- Sender: news@inews.Intel.COM (USENET News System)
- Organization: Intel Corporation, Santa Clara, CA USA
- Lines: 62
- Nntp-Posting-Host: td2cad
-
- Howdy,
-
- I've been working with OOP for a while, and only recently thought
- about needs for multiple inheritance (from a discussion in this newsgroup,
- I think), and I was wondering how something like that would be implemented
- in an efficient manner.
-
- I'm most familiar with C++, so I'll use that for examples...say my
- C++ compiler sees the following code:
-
- -------------------------------------------------------------------------------
-
- class parent {
- public:
- virtual int foo();
- int data;
- };
-
-
- class otherParent {
- public:
- int moreData;
- };
-
-
- class child : public parent,public otherParent {
- public:
- virtual int foo();
- int evenMoreData;
- };
-
- void main() {
- parent *p;
- otherParent *op;
- child c;
-
- p = &c;
-
- p->foo(); // How does the compiler reference
- printf("Data: %d\n",p->data); // these methods and attributes?
-
- op = &c;
- printf("More data: %d\n",op->moreData);
- }
-
- -------------------------------------------------------------------------------
-
- If multiple inheritance didn't exist, the offset of an attribute such
- as 'data' or 'moreData' from the start of the object's instance record would
- be the same regardless of what ancestor object type is actually realized.
-
- Seeing that multiple inheritance DOES exist, what would be the best
- method of dealing with it? For example, how does the compiler know where to
- find 'data' from the pointer 'p' which may or may not be pointing to an object
- which has multiple ancestors?
-
- Thanx for any help you can give!
-
- Dennis
- dmarer@td2cad.intel.com
-
- -- Not speaking for Intel
-