Hi,
edit @ferdinand:
How to implement a class that can be stored in a BaseArray
that has virtual member functions where a class instance is not copyable but moveable?
This is specifically about using the macro MAXON_OPERATOR_MOVE_ASSIGNMENT
.
let's say, I have a class like this, with a virtual function:
class SomeClass
{
MAXON_DISALLOW_COPY_AND_ASSIGN(SomeClass);
public:
virtual maxon::Result<void> PopulateArray()
{
// Fill _vectorArray with something
return maxon::OK;
}
virtual maxon::Result<void> CopyFrom(const SomeClass& src)
{
return _vectorArray.CopyFrom(src._vectorArray);
}
private:
maxon::BaseArray<maxon::Vector> _vectorArray;
public:
SomeClass()
{}
virtual ~SomeClass()
{}
SomeClass(SomeClass&& src)
{
// What to do with _vectorArray?
}
MAXON_OPERATOR_MOVE_ASSIGNMENT(SomeClass);
};
Since the class contains a maxon::BaseArray
, I decorated it with a MAXON_DISALLOW_COPY_AND_ASSIGN()
statement. Therefore, to use it in a BaseArray
, I have to implement a CopyFrom()
function and a move assignment operator. I also added a virtual destructor to avoid compiler error C4265.
Let's test it
SomeClass testObject;
maxon::BaseArray<SomeClass> testArray;
testArray.Append(testObject) iferr_return;
I get the error:
C2338: MAXON_OPERATOR_MOVE_ASSIGNMENT can't be used for classes with virtual functions.
So, long story short: How do I create arrays of classes that don't allow copy and assign, and also can't use MAXON_OPERATOR_MOVE_ASSIGNMENT
because they have virtual functions? Does that even work at all? And would it work with classes derived from SomeClass
?
Cheers,
Frank
edit @fwilleke80:
I guess, the easiest solution is to not store SomeClass objects in a BaseArray, but to store SomeClass* pointers in a PointerArray, right?