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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:28:35+00:00 2026-05-16T15:28:35+00:00

Essentially, what I’d like is for the value object to maintain a reference to

  • 0

Essentially, what I’d like is for the value object to maintain a reference to the corresponding key object, because there’s some useful information in there, which would be nice to access via the value object.

What I’m attempting to do may just not make sense, but consider the following:

class key
{
    // ... Various members ...
    friend bool operator< (const key &lhs, const key &rhs) { /* ... */ }
};

class value
{
public:
    value(const key &k) : k(k) {}
private:
     const key &k;
    // ... Various members ...

};


std::map<key,value> m;

// start a new scope, which may be due to e.g. function call, loop, etc.
{
    key k;  // I'm on the stack!

    m.insert(std::pair<key,value>(k, value(k)));
}

Of course, this doesn’t work, because this is a reference to a stack object, which breaks as soon as k goes out of scope. Is there somehow a way to get a reference back to the copy of the key maintained in the map?

  • 1 1 Answer
  • 2 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-16T15:28:36+00:00Added an answer on May 16, 2026 at 3:28 pm

    You could put the reference in place after insertion, but you’d have to make it a pointer:

    std::map<key, value>::iterator iter = m.insert(std::make_pair(k, v)).first;
    iter->second.setValue(&iter->first);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Essentially I want a border-less, black window which I can set the location and
Essentially, is there any way to make this code legal? main = print .
Essentially, I have a binary voting system Like/Dislike. Thee class is called Like It
Essentially I'd like to know just how compatible are the iPhone and the iPod
Essentially I have a method of a class called killProgram, which is intended to
Essentially, I want to check another object to see if an attribute is set
Essentially I've got a table holding user data, all of which is AES encrypted
Essentially, I would like to create a database structure that allows for classifying an
Essentially I would like to apply a bottom-border , but rather than being in
Essentially I'd like to achieve this: vars <- c(x1, x20, x37, etc) summary(data[vars]) However,

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.