KKitForma.

Language

EnglishEnglishTürkçeTurkishTool unavailable · open catalogDeutschGermanTool unavailable · open catalogEspañolSpanishTool unavailable · open catalogFrançaisFrenchTool unavailable · open catalogPortuguêsPortugueseTool unavailable · open catalogItalianoItalianTool unavailable · open catalogNederlandsDutchTool unavailable · open catalogPolskiPolishTool unavailable · open catalogРусскийRussianTool unavailable · open catalogУкраїнськаUkrainianTool unavailable · open catalogSvenskaSwedishTool unavailable · open catalogNorskNorwegianTool unavailable · open catalogDanskDanishTool unavailable · open catalogSuomiFinnishTool unavailable · open catalogČeštinaCzechTool unavailable · open catalogRomânăRomanianTool unavailable · open catalogΕλληνικάGreekTool unavailable · open catalogالعربيةArabicTool unavailable · open catalogעבריתHebrewTool unavailable · open catalogفارسیPersianTool unavailable · open catalogاردوUrduTool unavailable · open catalogहिन्दीHindiTool unavailable · open catalogবাংলাBengaliTool unavailable · open catalogதமிழ்TamilTool unavailable · open catalogతెలుగుTeluguTool unavailable · open catalogमराठीMarathiTool unavailable · open catalogગુજરાતીGujaratiTool unavailable · open catalog简体中文Chinese SimplifiedTool unavailable · open catalog繁體中文Chinese TraditionalTool unavailable · open catalog日本語JapaneseTool unavailable · open catalog한국어KoreanTool unavailable · open catalogTiếng ViệtVietnameseTool unavailable · open catalogไทยThaiTool unavailable · open catalogBahasa IndonesiaIndonesianTool unavailable · open catalogBahasa MelayuMalayTool unavailable · open catalogFilipinoFilipinoTool unavailable · open catalogKiswahiliSwahiliTool unavailable · open catalogAfrikaansAfrikaansTool unavailable · open catalogMagyarHungarianTool unavailable · open catalogБългарскиBulgarianTool unavailable · open catalogHrvatskiCroatianTool unavailable · open catalogSrpskiSerbianTool unavailable · open catalogSlovenčinaSlovakTool unavailable · open catalogSlovenščinaSlovenianTool unavailable · open catalogLietuviųLithuanianTool unavailable · open catalogLatviešuLatvianTool unavailable · open catalogEestiEstonianTool unavailable · open catalogCatalàCatalanTool unavailable · open catalogEuskaraBasqueTool unavailable · open catalog
← All topics and search

C++

Object lifetimes, templates, standard library and C++ build errors.

55 troubleshooting guides · Page 1 / 3

  1. Why is vector[i] invalid after reserve without resize?

    Reserve changes capacity, not the number of constructed elements. A vector with size zero still has no element at index zero.

  2. Why does a vector element reference break after push_back?

    Growth can reallocate vector storage and invalidate its old references, pointers and iterators. A cached address is not stable across arbitrary insertion.

  3. How do I erase vector elements without skipping or invalidating iteration?

    Erase shifts later elements and invalidates iterators at or after the erased position. Incrementing that old iterator is not a valid next-step operation.

  4. Why does changing auto item leave the container unchanged?

    For ordinary value elements, a by-value range-for variable is a copy. Changing it does not update the stored object.

  5. Why does auto from vector<bool> behave differently from bool?

    vector<bool> may return a proxy representing a stored bit rather than a normal bool reference. An auto variable can preserve that connection to the container.

  6. Why does std::remove leave vector size unchanged?

    The algorithm compacts retained elements and returns a new logical end. It does not own the container or change its physical size.

  7. Why does checking map[key] insert an unexpected value?

    Subscript is an access-or-insert operation. Using it to check a missing key can grow the map and create a default mapped value.

  8. Why does a case-insensitive unordered_map miss equivalent keys?

    Equivalent keys must produce equal hashes. Supplying case-insensitive equality with an unchanged case-sensitive hash violates that relationship.

  9. Why does unordered_map rehash invalidate iterators but not element references?

    Rehash changes bucket traversal, so iterator validity differs from the lifetime of the actual element object.

  10. Why does <= in a sort comparator produce erratic results?

    A sorting comparator must describe a strict ordering. Returning true for equal values breaks that contract.

  11. Why does lower_bound fail after sorting by a different field?

    The range must satisfy the search comparison’s partitioning requirement. Sorting by display name does not prepare a range for binary search by numeric identifier.

  12. Why does returning string_view from a temporary string produce garbage?

    string_view borrows characters without owning or extending their lifetime. A view into a temporary or local string can outlive its source immediately.

  13. Why can string_view.data() send extra text to a C string API?

    A view can end before its backing string’s null terminator. data() communicates an address, not the view’s length.

  14. Why does editing a string invalidate its saved c_str pointer?

    The pointer designates storage owned by the string. Mutating operations can invalidate that storage, so the pointer is not a snapshot.

  15. Why can I not copy unique_ptr into another owner?

    unique_ptr encodes exclusive ownership. An ordinary copy would create two cleanup responsibilities for the same resource, so that operation is intentionally unavailable.

  16. Why does unique_ptr.release leak my object?

    release returns the raw pointer and stops owning it; it does not destroy the resource. Ignoring the result leaves cleanup unassigned.

  17. Why does a second shared_ptr built from get() double-delete?

    The raw-pointer constructor creates another control block. Two unrelated ownership groups can then each attempt to destroy the same address.

  18. Why are mutually linked shared_ptr objects never destroyed?

    A strong-reference cycle can keep every count above zero after external owners disappear. Reference counting is not a cycle collector.

  19. Why is expired() followed by weak pointer access a race?

    Checking expiration and acquiring ownership are separate moments. The last strong owner can disappear between them.

  20. Why does shared_from_this fail in a constructor?

    During construction the object may not yet participate in the completed ownership mechanism required by shared_from_this. A raw new expression alone does not establish it.

  21. Why does std::move on a const value still copy?

    std::move changes expression category; it neither removes const nor forces a move overload to exist. A normal non-const rvalue-reference move constructor cannot consume a const source.

  22. Can I assume a moved-from std::string is empty?

    The general moved-from guarantee for many library types is valid but unspecified state unless a stronger rule is documented. Observing empty in one implementation is not a business postcondition.

  23. Why can return std::move(local) reduce return-value optimization?

    Returning a named local directly can permit named return value optimization. Wrapping it with std::move can prevent that particular optimization rather than improve it.

  24. Why does copying a class with a raw owning pointer double-free?

    A generated copy operation copies the pointer value, not the allocation it owns. Two objects can then attempt to release one resource.

Ask your own question · Sign in to post questions and answers.