Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Is it safe to free with super?

    SDK Help
    0
    4
    1.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

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

      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 );
      
      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        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)
        {
            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);  
        
        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          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

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

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

            Nice, thanks!

            1 Reply Last reply Reply Quote 0
            • First post
              Last post