Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9168541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:38:58+00:00 2026-06-17T15:38:58+00:00

I have a map declared as std::map< std::string, std::map<int,std::list<pointers*> > myMap; // in c++.

  • 0

I have a map declared as

std::map< std::string, std::map<int,std::list<pointers*> > myMap; // in c++.

May I know in order to delete an entry in this map, is it sufficient by calling myMap.erase(entryToBeDeleted)? Or should I go and iterate through the sub-map to delete everything first and then delete the entry?

To add on, the inner map is a map with int as key and a list of pointers as value

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:38:59+00:00Added an answer on June 17, 2026 at 3:38 pm

    It depends on the real type of the nested map, if it contains raw pointer, it’s your responsibilty to iterate though each item of nested map to deallocate the memory. Otherwise, myMap.erase(entryToBeDeleted) is sufficient.

    Edit:

    As your nested map has list of pointers, you need to go through each list inside each nested map to delete pointers.

    A better way is to use smart pointers:

    std::map< std::string, std::map<int,std::list<std::unique_ptr<pointers> > > myMap;
    

    When you delete nested map, the pointers will be deallocated automatically.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a std::map called 'prompts' which is declared like this: std::map<const int, wstring,
unordered_map<std::string,unordered_map<std::string, std::string> >* storing_vars; I have this variable in the scope declared in the
I have a map declared as follows: map < string , list < string
I have a multimap declared as: typedef multimap <int, std::string> MM; I was having
I have declared a map like this map<long long, list<SoundInfo *> > m_soundListMap; and
I have the following C++ code std::map<std::string, std::vector<std::vector<std::vector<double> > > > details details[string][index][index].push_back(123.5); May
I have something like this: #include <iostream> #include <map> int main() { std::map<int, int*>
Supposed I have a type I'll call NamedNestedMap std::map<std::string, std::map<std::string, NamedNestedMap> > In this
I declared std: map below: std::map<std::string, std::set<unsigned char*>> FilesMap; int InsertData(unsigned char* name) {
I have the following cyclic dependency problem I am trying to solve: typedef std::map<int,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.