[comp.sys.mac.programmer] Problems in ThinkC mixing direct and indirect objects

adiseker@potomac.ads.com (Andrew Diseker) (09/27/90)

	I have just had a problem in using an instance of a direct object
in the method of an indirect object.  This is part of the method code:

void  IndirectObj::aMethod()
{
   DirectObj  *tempObj;
       :
   tempObj = new( DirectObj );
   tempObj->someMethod(); <<< the debugger stops here with "odd address trap"
       :
   delete( tempObj );
}

   where someMethod() is declared and defined in the DirectObj class 
definition and code.  I changed DirectObj's definition from direct to 
indirect, and had no further problems.  Shouldn't I be allowed to mix 
types?  I do kind of like to have the choice. For example, if tempObj is 
small, and nothing I do to it will move memory, I want to eliminate the 
overhead involved with dereferencing handles.


-- 
Andrew Diseker   >Advanced Decision Systems   >UUCP: sun!sundc!potomac!adiseker
>Internet:adiseker@potomac.ads.com  "Indeed, many respected computer scientists
have difficulty with left and right even though they can manage the logical con-
nectives and can be left to write left to right the right Boolean operations"

siegel@endor.uucp (Rich Siegel) (09/27/90)

In article <9200@potomac.ads.com> adiseker@potomac.ads.com (Andrew Diseker) writes:

>void  IndirectObj::aMethod()
>{
>   DirectObj  *tempObj;
>       :
>   tempObj = new( DirectObj );
>   tempObj->someMethod(); <<< the debugger stops here with "odd address trap"
>       :
>   delete( tempObj );
>}
>
>   where someMethod() is declared and defined in the DirectObj class 
>definition and code.  I changed DirectObj's definition from direct to 
>indirect, and had no further problems.  Shouldn't I be allowed to mix 

	When using direct classes, the responsibility for storage management
is yours - you can't use new() and delete(). You might try something like:

void IndirectObj::method()
{
	DirectObj *tmp;

	tmp = NewPtr(sizeof DirectObj);
	tmp->itsMethod();
	DisposPtr(tmp);
}

The problem does not lie in your mixing of class types; it's that you need
to allocate storage for direct classes yourself.

R.
 Rich Siegel	Software Engineer	Symantec Languages Group
 Internet: siegel@endor.harvard.edu	UUCP: ..harvard!endor!siegel

If you have telekinetic powers, raise my hand.