Jump to content
  • Advertisement
Sign in to follow this  
thedustbustr

dangerous vector use due to scope?

This topic is 3880 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

class A { std::vector<std::pair<std::string, HWND> > v; void method() { std::pair<std::string, HWND> p("hello",0x0); v.push_back(p); } }; is this going to be bad news, because v is storing a reference to a p with local scope? is my only alternative to allocate a persistent p using new and remember to clean up later?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by thedustbustr
class A {
std::vector<std::pair<std::string, HWND> > v;

void method() {
std::pair<std::string, HWND> p("hello",0x0);
v.push_back(p);
}
};

is this going to be bad news, because v is storing a reference to a p with local scope? is my only alternative to allocate a persistent p using new and remember to clean up later?


No, because vector doesn't store references, it stores copies. It will call the copy constructor of the std::pair and store a copy.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!