double pointer reference in C++ -


this may stupid question, i'm gonna ask anyway:

suppose have pointer: object* pointer points @ dynamically allocated object.

class pointclass {  array<object*> m_array1;  array<object*> m_array2;   void delete1()  {      (int = 0; < m_array1.length; i++)      {          delete m_array1[i];      }  }  void delete2() {     (int = 0; < m_array2.length; i++)     {         delete m_array2[i];     }  } } 

now, put pointer both in m_array1 , in m_array2.

when try delete arrays, in 1 of them have pointer points deallocated space, can't delete again!

i can't assign pointers null after deletion because wouldn't affect pointer in other array.

how solve it?

well simplest way use reference-counting pointer, available in boost::smart_ptrs.

otherwise, need assign owners pointers - need decide class responsible allocating/deleting particular pointer. if reason decide should this class, remove duplicates arrays adding pointers set before enumerating them.


Comments

Popular posts from this blog

how to build hyperlink for query string in php -

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

queue - mq_receive: message too long -