Does C++ support \'finally\' blocks?
What is the RAII idiom?
What is the difference between C++\'s RAII idiom and C#\'s \'using\' statement?
As many people have stated, the solution is to use C++11 features to avoid finally blocks. One of the features is unique_ptr.
Here is Mephane's answer written using RAII patterns.
#include
#include
#include
using namespace std;
class Foo
{
...
};
void DoStuff(vector input)
{
list > myList;
for (int i = 0; i < input.size(); ++i)
{
myList.push_back(unique_ptr(new Foo(input[i])));
}
DoSomeStuff(myList);
}
Some more introduction to using unique_ptr with C++ Standard Library containers is here