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 7700527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:43:47+00:00 2026-05-31T22:43:47+00:00

From a C background I find myself falling back into C habits where there

  • 0

From a C background I find myself falling back into C habits where there is generally a better way. In this case I can’t think of a way to do this without pointers.

I would like

struct foo {
    int i;
    int j;
};

mymap['a'] = foo
mymap['b'] = bar

As long as only one key references a value mymap.find will return a reference so I can modify the value, but if I do this:

mymap['c'] = mymap.find('a') // problematic because foo is copied right?

The goal is to be able to find ‘a’ or ‘c’ modify foo and then the next find of ‘a’ or ‘c’ will show the updated result.

  • 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-05-31T22:43:48+00:00Added an answer on May 31, 2026 at 10:43 pm

    No, you will need to use pointers for this. Each entry in the map maintains a copy of the value assigned, which means that you cannot have two keys referring to the same element. Now if you store pointers to the element, then two keys will refer to two separate pointers that will refer to the exact same in memory element.

    For some implementation details, std::map is implemented as a balanced tree where in each node contains a std::pair<const Key,Value> object (and extra information for the tree structure). When you do m[ key ] the node containing the key is looked up or a new node is created in the tree and the reference to the Value subobject of the pair is returned.

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

Sidebar

Related Questions

I come from a c++ background and I find myself constantly doing this in
As a developer coming from a Windows background, I'd always find the different Powertoys
I can hookup to AppDomain.CurrentDomain.UnhandledException to log exceptions from background threads, but how do
I couldn't find any good application for streaming MP3s from a URL that can
How can I fade from one background-color to another color in a UIView? In
Background: On a new project I've found myself 3 levels removed from my actual
I may lack the mathematical background to find the right answer for myself. I
I want to load 4 images from background showing a load bar to the
I'm trying to migrate to NewsstandKit to benefit from background download. I'm being able
Coming from a background, I'm familiar with GUI editors that do a poor job

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.