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.