Is it safe to free with super?

On 02/05/2018 at 12:47, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R19 
Platform:   Windows  ; Mac  ;  Mac OSX  ; 
Language(s) :


Is it safe to do this...?

PolygonObject* polygon = PolygonObject::Alloc( pointCount, polygonCount );
// Fill polygon
BaseObject* baseObject = static_cast<BaseObject *>( polygon );
BaseObject::Free( baseObject );

On 02/05/2018 at 20:13, xxxxxxxx wrote:

I think it may be the same, both ::Free calls do the exact same function (if you look at the definition).

void PolygonObject::Free(PolygonObject*& bl)
    bl = nullptr;
void BaseObject::Free(BaseObject*& bl)
    bl = nullptr;

and the Free function is a library function declared as:

void (*Free)(C4DAtom *at);  

On 04/05/2018 at 13:55, xxxxxxxx wrote:

Hi rsodre, i confirm that, although not representing an ordinary approach, you can safely use the parent's Free method to destroy a derived class.

Best, Riccardo

On 04/05/2018 at 16:36, xxxxxxxx wrote:

Nice, thanks!