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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:40:01+00:00 2026-06-14T20:40:01+00:00

I am using C++ std vector to store render objects for a simple scene

  • 0

I am using C++ std vector to store render objects for a simple scene graph implementation.I need an ability to add and remove render objects in run time from the scene graph.Adding is not a problem,for removing: reading docs for vector and other C++ containers it appears that when objects are popped their destructors are called.That is not what I need because I want to be able to re-add those objects later to the rendering loop.What are the possible solution to this problem?
Important detail I forgot to mention -I am using vector of pointers to the render objects.

  • 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-14T20:40:02+00:00Added an answer on June 14, 2026 at 8:40 pm

    It seems you’re confused with the basic concept of object instances. When you add something to a vector, you don’t move it into it, you copy it:

    vector<string> vec;
    string s;
    vec.push_back(s);
    

    vec[0] is not s, it’s a copy of s. So when you remove it from the vector, s is not affected.

    If you don’t want copies, you should switch to pointers instead. You can them remove the pointers from the vector and the destructor of the object they point to will not be called.

    Edit:
    OK, it seems you’re already using pointers. You said:

    reading docs for vector and other C++ containers it appears that when
    objects are popped their destructors are called

    That is true. When you remove a pointer from the vector, the pointer is getting destroyed. That’s what the docs mean. It doesn’t mean that the object the pointer points to is getting destroyed:

    vector<string*> vec;
    string s;
    vec.push_back(&s);
    vec.pop_back();
    

    s is not affected at all. What gets destroyed by the pop operation is the pointer that holds the address of s, not s itself.

    So you’re fine.

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

Sidebar

Related Questions

I am using a std::vector to store an array of objects that are referenced
What am I doing wrong? #include <vector> #include <boost/graph/adjacency_list.hpp> #include <boost/graph/dijkstra_shortest_paths.hpp> using namespace std;
I am using a datatype of std::vector<std::vector<T> > to store a 2D matrix/array. I
I want to store a list of objects in an std::vector , but the
I am using vector as a buffer to store some objects to be later
I am using a std::vector to store some strings, later I try to std::find
I'm using a std::deque to store a fairly large number of objects. If I
I am using WaitForMultipleObject function with waitForAll parameter = true. Here using a std::vector
#include <iostream> using namespace std; // This first class contains a vector and a
When trying to compile this code: #include <iostream> #include <vector> using namespace std; class

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.