stl - C++ List of objects are only copies -


i find myself needing keep 2 lists of objects performance reasons (speed on memory).

i'm using object pointers such as

std::list<myclass*> m_list1; std::list<myclass*> m_list2; 

i add objects list by

myclass* myobject = new myclass(); m_list1.push_back(myobject); m_list2.push_back(myobject); 

the problem i'm facing changes make m_list1 not affecting m_list2, copies , not real deal.

what correct way store these won't copies? not using pointers isn't option these allocated on heap.

std containers copy values passed in, since passed in pointers, pointers copied. therefore still pointing same object. problem must somewhere else. perhaps post specific code think exhibiting behavior?


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -