[comp.sys.mac.programmer] MPW C++ - MI and HandleObject

shite@unf7.UUCP (Stephen Hite) (04/13/90)

  The Apple C++ reference says that multiple inheritance cannot be
used in combination with HandleObject.  Why not?  Also, why is it 
not possible to allocate an array of handle-based objects?  Will these
restrictions possibly be lifted in the future? 

  Thanks to the object specialists at Apple for answering this.  

-----------------------------
Steve Hite
...gatech!uflorida!unf7!shite

amanda@mermaid.intercon.com (Amanda Walker) (04/13/90)

In article <255@unf7.UUCP>, shite@unf7.UUCP (Stephen Hite) writes:
> The Apple C++ reference says that multiple inheritance cannot be
> used in combination with HandleObject. 

It's an artifact of the way multiple inheritance is implemented in C++.
In simple terms, pointers are indistinguishable, so you can take a pointer
to a block of instance variables and pretend it's an object in its own
right.  You can't make a Handle that refers to a piece of another Handle...

--
Amanda Walker, InterCon Systems Corporation
--
"Y'know, you can't have, like, a light, without a dark to stick it in...
 You know what I'm sayin'?"     --Arlo Guthrie

beard@ux1.lbl.gov (Patrick C Beard) (04/14/90)

In article <255@unf7.UUCP> shite@unf7.UUCP (Stephen Hite) writes:
#
#  The Apple C++ reference says that multiple inheritance cannot be
#used in combination with HandleObject.  Why not?  Also, why is it 
#not possible to allocate an array of handle-based objects?  Will these
#restrictions possibly be lifted in the future? 
#
#  Thanks to the object specialists at Apple for answering this.  
#

Well, I'm no object specialist, but I'll give it a whirl.

As I understand it, Multiple-Inheritance is implemented by generating
code that does address arithmetic on the this pointer to an instance of an 
object, which is bad because this is a handle for handle-based objects.
On pg. 37 of the latest MPW 3.1 C++ reference manual it says that no address
arithmetic may be performed on a pointer to a handle based object, except 
for the implicit arithmetic of a member reference.  So, I suppose that since 
Apple hasn't gotten around to implementing address arithmetic for these classes,
that's why MI can't be used.

In theory, I believe that MI should be doable using Handle based classes.  I
think the best way to do it for now, would be to do away with the implicit 
references that Object Pascal uses, such as:

  MyHandleClass* mhc = new MyHandleClass;
  mhc->methodCall();

and move to a more explicit use of Handles:

  MyClass** mc = new MyClass;  // new overloaded to return void**, not
                               // just void*, or how about hnew to return
                               // handles...

  (**mc).methodCall();         // call handle allocated class.

                               // this would be a pointer, as it is
                               // in the automatically allocated case, 
                               // (*this).field would be generated
                               // for every member reference in the method.

Now, since this is a pointer to the object that was allocated as a handle, 
member references could be unsafe.  Instead of writing methods that know that
they are handle based, one could implement a Lock method that could be called 
before pointer references are used:

  (**mc).Lock();               // lock the this pointer for pointer access.
  MyClass* mcptr = *mc;

  mcptr->methodCall();         // call with pointer reference.


This would allow both handle implemented classes AND Multiple Inheritance.

Any object specialists listening?



-------------------------------------------------------------------------------
-  Patrick Beard, Macintosh Programmer                        (beard@lbl.gov) -
-  Berkeley Systems, Inc.  ".......<dead air>.......Good day!" - Paul Harvey  -
-------------------------------------------------------------------------------