First, of course, the virtual question was about an inherited class. I can't say why but even without the "virtual" keyword, my destructors are correctly called. lets say its ok ...
I wrote a personnal version of new/delete inspired from palmoswerks.com :
////////////////////////////////////////// void operator delete(void* ptr) { if (ptr) MemPtrFree(ptr); }
//////////////////////////////////////////
void* operator new(std::size_t size)
{
if (size == 0)
size = 1;
return MemPtrNew(size);
}I wrote them in a .cpp and added a .h with :
#include <new> void operator delete(void* ptr); void* operator new(std::size_t size);
this .h is included everywhere through the settings C++ language / prefix file.
It seams to work correctly on palm tungsten and palm 515. I am going wrong ?
Thanks
Ben Combee wrote:
I have learnt that every C++ class should have a virtual destructor, because of inheritance implementation, virtual ensure that the good destructor is called.
C++ classes should only have virtual destructors when they can be inherited. There are plenty of uses of classes that don't support inheritance. Do you need to inherit from a CString? Often, inheritance is better replaced by encapsulation and aggregation anyway.
Moreover, it is written in doc "targeting_palm_os.pdf" that new and delete cant be called if !sysAppLaunchFlagNewGlobals because they throw exceptions and this needs globals.
That's right. You can use inline versions of new/delete (see palmoswerks.com) to avoid this issue.
HOW CAN YOU PROGRAM IN C++ IN THOSE CONDITIONS ???
Very well. Just avoid the trouble spots, and use a mixture of OOP and procedural programming to handle launches where globals aren't available.
-- Riccardo Cohen
Articque Les Roches 37230 Fondettes France web = http://www.articque.com tel: +33 02 47 49 90 49 fax: +33 02 47 49 91 49
-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/
