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

    Move/Copy Constructors documentation

    Cinema 4D SDK
    r19 r20 c++
    2
    2
    699
    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.
    • C4DSC
      C4DS
      last edited by

      First of all I am trying to add a "documentation issue" tag, but cannot find anything related to documentation, only issue. So forgive my limited tagging.

      Right then, the actual issue I am facing:
      I am trying to provide a base class and a derived class, and following the "Move/Copy Constructors" page from the R19 SDK documentation. (Cannot seem to find this in the R20 documentation).

      Anyway, I follow the directives to provide a move and assignment operator, and do this in the base and derived class. All fine.
      The base class is POD class, and technically doesn't require a move/copy constructor, but since the derived one needs this, I also perform the move of the base in the derived move constructor:

      Base::Base(Base&& src) :
      	member1(std::move(src.member1)),
      	member2(std::move(src.member2))
      {}
      
      Derived::Derived(Derived&& src) :
      	Base(std::move(src)),
      	memberA(std::move(src.memberA)),
      	memberB(std::move(src.memberB))
      {}
      

      But when it comes to the CopyFrom method, I am somewhat confused.
      Performing only the necessary copy on the derived member does clear out the base class member
      when adding an instanciated derived class to a BaseArray.

      So I thought to perform the copy of the base members inside the CopyFrom of the derived class.

      maxon::Bool Derived::CopyFrom(const Derived& src)
      {
      	// copy members of the base class
      	member1 = src.member1;
      	member2 = src.member2;
      	// etc
      
      	// copy members of the derived class
      	memberA = src.memberA;
      	memberB = src.memberB;
      	// etc
      	return TRUE;
      }
      

      This seems to work, but I would prefer some sort of copying to be provided by the base class, which I could call somehow from within the derived class.

      As such I went ahead and did:

      maxon::Bool Base::CopyFrom(const Base& src)
      {
      	member1 = src.member1;
      	member2 = src.member2;
      	// etc
      	return TRUE;
      }
      
      maxon::Bool Derived::CopyFrom(const Derived& src)
      {
      	Base::CopyFrom(src);
      
      	memberA = src.memberA;
      	memberB = src.memberB;
      	// etc
      	return TRUE;
      }
      
      

      Where member1, member2 are members of the Base class, and memberA, memberB are members of the Derived class.

      So, you might think "Well, what's the question"?
      To which I will have to admit having actually resolved the question I had, while writing this post ...
      Still, I didn't want to deprive others potentially looking for an answer to this (already answered) question.

      1 Reply Last reply Reply Quote 1
      • a_blockA
        a_block
        last edited by a_block

        Hi,

        in general your approach looks correct to us.

        Somehow I'm starting to regret we have a thoughtful and attentive community here. We can not hide a single change/omission in the docs without any one of you finding out about it... sigh! 😉

        Yes, indeed the "Move/Copy Constructors" manual has been removed from the R20 docs, as it needed thorough review and at least partly rewriting we did not find the time for, yet. But it wasn't removed without at least partial replacement. Especially for your case the BaseArray manual contains a section on implementing classes for use with BaseArray.

        Thanks for the idea of a "documentation issue" tag.

        Cheers,
        Andreas

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