Size of vector

  • I have declared
    std::unique_ptr<std::vector<std::unique_ptr<Album>>> m_albums;
    but when I try to find the number of elements by calling
    it leads to a crash, presumably because no memory is not yet allocated for m_albums. What is the correct way out of this, so that I can call
    even before adding any elements to the the vector?

  • Lifetime Qt Champion

    C++ Basics - you forgot to initialize your shared_ptr.
    But why to use a shared_ptr in the first place here?

Log in to reply