Skip to content
Snippets Groups Projects
Commit dc66d7c2 authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Merge branch 'sponce_smartVectorFix' into 'master'

Better way of filling vector in smartPointer exercise

See merge request !19
parents d36ae97a 12774445
No related branches found
No related tags found
1 merge request!19Better way of filling vector in smartPointer exercise
......@@ -50,8 +50,7 @@ void problem1() {
try {
doStuffWithData();
} catch (std::exception& e) {
std::cerr << "problem1(): Do stuff with data terminated with exception:\n" << e.what()
<< "\n We may have a memory leak now." << std::endl;
std::cerr << "problem1(): Do stuff with data terminated with exception:\n" << e.what() << std::endl;
}
}
......@@ -155,9 +154,10 @@ void processElement(const LargeObject* /*element*/) { }
// model, this becomes a mess.
void problem3() {
// Let's generate a vector with 10 pointers to LargeObject
std::vector<std::shared_ptr<LargeObject>> objVector(10);
for (auto& ptr : objVector) {
ptr.reset(new LargeObject());
std::vector<std::shared_ptr<LargeObject>> objVector;
objVector.reserve(10);
for (unsigned int i = 0; i < 10; i++) {
objVector.emplace_back(new LargeObject());
}
// Let's copy it
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment