Note that there are some explanatory texts on larger screens.

plurals
  1. POEXC_BAD_ACCESS, when accessing the object pointed by the vector of pointers
    primarykey
    data
    text
    <p>I have a vector of pointers..</p> <p>I want to access my Image object via the pointer stored in the std::vector. After the iterator finds my object, I want to access/modify certain members of the Image object being pointed by the pointer in a vector.</p> <p>Please help !!</p> <hr> <pre><code>class Image; typedef std::vector &lt;Image*&gt; VecImages; typedef VecImages::iterator ImagesIter; class My_Images { private: VecImages m_Images; public: My_Images() {} ~My_Images(); void addImage(Image* img) {m_Images.push_back(img);} Image* getImage(string&amp; rID); }; // get image method Image* My_Images::getImage(string&amp; rID) { ImagesIter foundImg = m_Images.begin(); while (foundImg != m_Images.end()) { Image* img = *foundImg; ***&lt;&lt;&lt;&lt;----------- [EXC_BAD_ACCESS is reported here]*** const string &amp;strID = img-&gt;get_strRId(); if (strID == rID) { return (*foundImg); } ++foundImg; } return NULL; } // get-id method const string&amp; Image::get_strRId(void) {return m_strRId;} // copy constructor Image::Image(const Image&amp; _src) : m_strRId(_src.m_strRId) {} </code></pre> <p>I have another class named builder ... and there I'm invoking the addImage() method like this ... My_Images *m_images; (I create this 'new') Image *currImg = new Image; currImg->setName("ABC"); ... and several other 'set' functions are called on currImg (mainly setting std::string's).</p> <p>And then I add it into the vector using following call.</p> <p>m_images->addImage(currImg);</p> <p>And once this is stored in the vector, I giveup it's ownership. currImg = NULL;</p> <hr> <pre><code>template &lt;class _Type&gt; _Type* ChAutoPtr&lt;_Type&gt;::giveUpOwnership() { #ifdef VERIFY_WITH_SHADOW_STACK // Check to see if the last auto-ptr is the one that is being // given up!!! if (m_pInstance != NULL) { void* pTop = g_cleanupStackShadow.top(); ChASSERT(pTop == m_pInstance); g_cleanupStackShadow.pop(); } #endif /* _DEBUG */ _Type* pTmp = m_pInstance; m_pInstance = NULL; return pTmp; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload