T
tech
Hi, i have a std::vector of pointers to base classes say
std::vector<element*> m_elements;
how do i make the followin exception safe
function()
{
element* e= new DerivedElement;
m_elements.push_back(element);
}
the push back operation can throw so i can leak element if it throws
i thought of doing this but it still has the same problem as e.get()
gets executed first
then if the push back throws i leak the pointer. How to solve?? I
can't use
Boost on this project so the shared_ptr is not an option
function()
{
std::auto_ptr <element> e(new DerivedElement);
m_elements.push_back(e.get());
}
std::vector<element*> m_elements;
how do i make the followin exception safe
function()
{
element* e= new DerivedElement;
m_elements.push_back(element);
}
the push back operation can throw so i can leak element if it throws
i thought of doing this but it still has the same problem as e.get()
gets executed first
then if the push back throws i leak the pointer. How to solve?? I
can't use
Boost on this project so the shared_ptr is not an option
function()
{
std::auto_ptr <element> e(new DerivedElement);
m_elements.push_back(e.get());
}