If i have the following
Code:
class Test
{
..
Test(const Test&)
{
*mapPtr = *(Test.mapPtr); // is this enough??
}
private:
QScopedPointer<QMap<int, QSharedPointer<Test>>> mapPtr;
}
Printable View
If i have the following
Code:
class Test
{
..
Test(const Test&)
{
*mapPtr = *(Test.mapPtr); // is this enough??
}
private:
QScopedPointer<QMap<int, QSharedPointer<Test>>> mapPtr;
}
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:
Code:Test(const Test& other) : mapPtr(new QMap<int, QSharedPointer<Test>>(*other.mapPtr))
{
}