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

  • Home
  • SEARCH
  • 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 8871359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:58:23+00:00 2026-06-14T17:58:23+00:00

I just asked a question involving std::set but after thinking about it some more,

  • 0

I just asked a question involving std::set but after thinking about it some more, I think I’ve narrow down my problem to something simple.

I have a set of unique items. I’d like to create a vector where each element in the vector points to an item in the set.

So, I have a set of (unique) A objects:

class A
{
    int i;
};

std::set<A, compareclass> mySet;

and a vector of A*:

std::vector<A*> myVec;

set::insert() returns a pair which includes an iterator to the element (inserted or already existing) in the set. I could technically get it’s address like so:

ret = myset.insert(A());
myVec.push_back(&(*ret.first));   

I’m thinking that might not be a great idea, though. Is there any other way to allow a vector element to point to a specific object in the set?

  • 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-14T17:58:24+00:00Added an answer on June 14, 2026 at 5:58 pm

    I'm thinking that might not be a great idea, why do you think that? The only thing I see you is that you could do is to use something along the lines of a smart pointer instead of a plain pointer to clarify ownership, and avoid memory leak mistakes that come along with them.

    Or like suggested by Jerry, iterators are even better!

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

Sidebar

Related Questions

I just asked a question about this but I want to go at it
I've just asked question about Task but realized that I actually want to ask
I just asked this question Multiple Where conditions , but realised there was more
I recently asked just about the same question, but this one got a little
I know I've just asked a question about this, but I cannot figure out
I just asked a question about ordering but it was only the first part
I just asked a question here, about why an iframe_resize function wasn't working. After
Just asked a question about linking Boost libraries in the make file. Thanks to
I've just asked a question about an hour ago, while waiting for replies, I've
I have just asked this question an hour ago but with regards to IE8

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.