On 06 Apr 2001 10:33:04 -0700, Scott Johnson (Bellevue) wrote:
> > From: Dave Carrigan [mailto:[EMAIL PROTECTED]]
> > As an aside, if you're using C++, it's way better to cast using
> > theptr = static_cast<Char *>(MemHandleLock(handle))
>
> Or if you really want to show off:
>
> template <class T>
> inline T * MemHandleLock( MemHandle h )
> {
> return static_cast<T *>( MemHandleLock( h ));
> }
>
> And then use it like this:
>
> Foo * pFoo = MemHandleLock<Foo>( hFoo );
>
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)));
}
FieldType* field = GetObjectPtr<FieldType>(myform, myfieldid);
--
Dave Carrigan <[EMAIL PROTECTED]>
"UNIX-Apache-Perl-Linux-Firewalls-LDAP-C-DNS-PalmOS-XML"
Seattle, WA, USA
http://www.rudedog.org/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/