home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / object / 4562 < prev    next >
Encoding:
Text File  |  1992-12-16  |  1.9 KB  |  75 lines

  1. Path: sparky!uunet!olivea!inews.Intel.COM!td2cad!dmarer
  2. From: dmarer@td2cad.intel.com (Dennis Marer)
  3. Newsgroups: comp.object
  4. Subject: Implementation of multiple inheritance?
  5. Keywords: multiple inheritance
  6. Message-ID: <BzDnvq.H86@inews.Intel.COM>
  7. Date: 17 Dec 92 00:26:13 GMT
  8. Sender: news@inews.Intel.COM (USENET News System)
  9. Organization: Intel Corporation, Santa Clara, CA USA
  10. Lines: 62
  11. Nntp-Posting-Host: td2cad
  12.  
  13. Howdy,
  14.  
  15.     I've been working with OOP for a while, and only recently thought
  16. about needs for multiple inheritance (from a discussion in this newsgroup,
  17. I think), and I was wondering how something like that would be implemented
  18. in an efficient manner.
  19.  
  20.     I'm most familiar with C++, so I'll use that for examples...say my
  21. C++ compiler sees the following code:
  22.  
  23. -------------------------------------------------------------------------------
  24.  
  25. class parent {
  26. public:
  27.     virtual int foo();
  28.     int data;
  29. };
  30.  
  31.  
  32. class otherParent {
  33. public:
  34.     int moreData;
  35. };
  36.  
  37.  
  38. class child : public parent,public otherParent {
  39. public:
  40.     virtual int foo();
  41.     int evenMoreData;
  42. };
  43.  
  44. void main() {
  45.     parent *p;
  46.     otherParent *op;
  47.     child c;
  48.  
  49. p = &c;
  50.  
  51. p->foo();                // How does the compiler reference
  52. printf("Data: %d\n",p->data);        //  these methods and attributes?
  53.  
  54. op = &c;
  55. printf("More data: %d\n",op->moreData);
  56. }
  57.  
  58. -------------------------------------------------------------------------------
  59.  
  60.     If multiple inheritance didn't exist, the offset of an attribute such
  61. as 'data' or 'moreData' from the start of the object's instance record would
  62. be the same regardless of what ancestor object type is actually realized.
  63.  
  64.     Seeing that multiple inheritance DOES exist, what would be the best
  65. method of dealing with it?  For example, how does the compiler know where to
  66. find 'data' from the pointer 'p' which may or may not be pointing to an object
  67. which has multiple ancestors?
  68.  
  69.     Thanx for any help you can give!
  70.  
  71.                 Dennis
  72.                 dmarer@td2cad.intel.com
  73.  
  74. -- Not speaking for Intel
  75.