[comp.sys.mac.programmer] Pointers to Methods

ar4@mace.cc.purdue.edu (Piper Keairnes) (08/22/90)

Is it possible to get a pointer to a method in ThinkC 4.0?? I've dug
through the manuals, I've searched through code, and I've come up
empty. I know the way that C++ does it and that seems fairly straight
forward, but the ThinkC compiler won't allow what I've been trying.

HELP!!!

--Piper Keairnes
ar4@mace.cc.purdue.edu

wilkins@jarthur.Claremont.EDU (Mark Wilkins) (08/22/90)

In article <5378@mace.cc.purdue.edu> ar4@mace.cc.purdue.edu (Piper Keairnes) writes:
>Is it possible to get a pointer to a method in ThinkC 4.0?? I've dug
>through the manuals, I've searched through code, and I've come up
>empty. I know the way that C++ does it and that seems fairly straight
>forward, but the ThinkC compiler won't allow what I've been trying.


  Because objects are defined (internally) as handles, and are not locked
down unless a method is executing, getting a pointer to a particular
object's method is unreliable.

  That's an oversimplification but it gets the idea across.  If there is a
particular object whose method you want to have called the way to do it is
this:

 Define a global function which is NOT a method and use it to call the
method for a given object.  For example:



void FreeObject(CObject *myObject)
{
	myObject->Dispose();
}


  You can take this function FreeObject and pass a pointer to it anywhere
you like, without invoking the compiler's wrath.  The reason this works is
essentially that the object reference doesn't get resolved when the
pointer's value is calculated but rather when the function is called.

-- Mark Wilkins