CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2002

    Do i need to deep copy container object?

    If i have the following

    class Test
    Test(const Test&)
    *mapPtr = *(Test.mapPtr); // is this enough??
    QScopedPointer<QMap<int, QSharedPointer<Test>>> mapPtr;

  2. #2
    Join Date
    Jan 2006

    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))
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.