> -----Original Message-----
> From: Jeff Ishaq
> Sent: Monday, April 17, 2000 7:38 PM
> To: Palm Developer Forum
> Subject: RE: Movable class objects? This is kind of strange...
>
>
> > -----Original Message-----
> > From: Alexander Hinds [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, April 17, 2000 6:35 PM
> > To: Palm Developer Forum
> > Subject: RE: Movable class objects? This is kind of strange...
> > <LYR3523-4367-2000.04.17-13.19.26--ahinds#backupbuddy.com@news
> > .palmos.co
> > m>
> >
> > You may want to read about overriding operators new&delete,
> > and "placement
> > new" in Soustroup's C++ Programming Language and the C++ FAQ,
> > for starters.
It appears that the bottom line is this - you can't override a placement new
operator using CW6.
I read up on it, and tried to implement it a placement form of the new
operator in CW6. Codewarrior won't let me! Apparently the only kind of
operator new overrides I can do are those defined as such:
#pragma overload extern void *operator new(size_t) throw(bad_alloc);
#pragma overload extern void *operator new(size_t,const nothrow_t&)
throw();
#pragma overload extern void operator delete(void *) throw();
#if __MWERKS__>=0x2020
#pragma overload extern void *operator new[](size_t)
throw(bad_alloc);
#pragma overload extern void *operator new[](size_t,const nothrow_t&)
throw();
#pragma overload extern void operator delete[](void *) throw();
#endif
The MSL C++ reference reiterates this on page 53 of the PDF file, section
17.4.3.4.
If you attempt to overload the new operator with a 'place' argument, as
such:
void* operator new( size_t size, void* place ) { return place; }
I get "illegal 'operator' declaration."
My only alternative at this point is to do it manually. That is:
{
static VoidHand hMem = MemHandleNew( sizeof(MyClass));
VoidPtr pMem = (VoidPtr) MemHandleLock( hMem );
MyClass myClassInstance(5, true ); // some c'tor args
MemMove( pMem, &myClassInstance, sizeof(MyClass));
MemHandleUnlock( hMem ) ; pMem = NULL;
// To use:
MyClass* pMyClass = (MyClass*) MemHandleLock( hMem );
pMyClass->someFunction();
MemHandleUnlock( hMem );
}
In my testing, it seems you only need to do the MemMove() if your class has
virtual functions.
-Jeff Ishaq
Vanteon (formerly The Windward Group)
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html