Plugin Cafe Homepage
Forum Home Forum Home > Plugin Cafe > SDK Help
  New Posts New Posts
  FAQ FAQ  Forum Search   Register Register  Login Login

Is it safe to free with super?

 Post Reply Post Reply
Author
Message
rsodre View Drop Down
Member
Member


Joined: 2014 Jun 15
Location: Brazil
Online Status: Offline
Posts: 89
Post Options Post Options   Quote rsodre Quote  Post ReplyReply Direct Link To This Post Topic: Is it safe to free with super?
    Posted: 2018 May 02 at 12:47pm

User Information:

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

---------

H!

Is it safe to do this...?

PolygonObject* polygon = PolygonObject::Alloc( pointCount, polygonCount );

// Fill polygon

BaseObject* baseObject = static_cast<BaseObject *>( polygon );

BaseObject::Free( baseObject );


Edited by rsodre - 2018 May 02 at 12:48pm
Back to Top
MohamedSakr View Drop Down
Member
Member
Avatar

Joined: 2012 Sep 17
Location: Egypt
Online Status: Offline
Posts: 577
Post Options Post Options   Quote MohamedSakr Quote  Post ReplyReply Direct Link To This Post Posted: 2018 May 02 at 8:13pm
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)
{
    C4DOS.Bl->Free(bl);
    bl = nullptr;
}

void BaseObject::Free(BaseObject*& bl)
{
    C4DOS.Bl->Free(bl);
    bl = nullptr;
}

and the Free function is a library function declared as:

void (*Free)(C4DAtom *at);



Edited by MohamedSakr - 2018 May 02 at 8:18pm
cheers,
Mohamed Sakr
Back to Top
knickknack View Drop Down
Forum Moderator
Forum Moderator


Joined: 2016 Jul 01
Location: Italy
Online Status: Offline
Posts: 261
Post Options Post Options   Quote knickknack Quote  Post ReplyReply Direct Link To This Post Posted: 2018 May 04 at 1:55pm
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
MAXON Computer GmbH
SDK Support Team
Back to Top
rsodre View Drop Down
Member
Member


Joined: 2014 Jun 15
Location: Brazil
Online Status: Offline
Posts: 89
Post Options Post Options   Quote rsodre Quote  Post ReplyReply Direct Link To This Post Posted: 2018 May 04 at 4:36pm
Nice, thanks!
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Bulletin Board Software by Web Wiz Forums® version 9.61 [Free Express Edition]
Copyright ©2001-2009 Web Wiz

This page was generated in 0.109 seconds.