August 5th, 2014, 03:01 AM
Do i need to deep copy container object?
If i have the following
*mapPtr = *(Test.mapPtr); // is this enough??
QScopedPointer<QMap<int, QSharedPointer<Test>>> mapPtr;
August 5th, 2014, 03:34 AM
Re: Do i need to deep copy container object?
Reading docs that I found online, it seems that QScopedPointer is not copyable. This makes sense since it is neither "shared" nor "unique" but rather is "scoped". Since Test has a member of type QScopedPointer, it follows that Test should not be copyable. Hence, you should disable the copy constructor instead of trying to implement it.
If you do want to implement the copy constructor, then indeed you need to do a deep copy. Unfortunately, what you wrote will not work because you need to give the reference to the Test object that you are copying from a name, and then you need to create a new QMap object to copy to (otherwise you're dereferencing a null pointer), maybe something like:
Test(const Test& other) : mapPtr(new QMap<int, QSharedPointer<Test>>(*other.mapPtr))
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!