Dave Carrigan wrote:
> 
> Yes, and this technique is also very useful for implementing a typesafe
> C++ GetObjectPtr function.
> 
> template <class T>
> inline T* GetObjectPtr(FormType* frm, const UInt16 item)
> {
>   return static_cast<T*>(FrmGetObjectPtr(frm, FrmGetObjectIndex(frm,
> item)));
> }

I'd only consider this to be safe if it checked for the correct object
kind:

template <typename T>
void GetObjectPtr(T * &result,
                  UInt16 index,
                  FormType *frmP = FrmGetActiveForm())
{
  ErrFatalDisplayIf(FrmGetObjectType(frmP,index)!=traits<T>::kind,
                    "Invalid Form object cast attempted!");

  return static_cast<T *>(FrmGetObjectPtr(frmP,index));
}

with traits specializations for all appropriate types.

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to