Say I have the following code(this is just an example, obviously not practical):
std::list <Object> objects;
Object cur_object;
for(int i = 0; i < 11; i++){
switch(i){
case 0:
cur_object.foo = true;
break;
case 5:
case 10:
objects.push_back(cur_object);
Object cur_object; //Line in question
break;
default:
cur_object.bar = i;
break;
}
}
What is the most effective and efficient way to "reset" the cur_object for the next pass. For example, I don't believe cur_object = *new Object is correct. Would it be best for the class to have a reset method?
Solution:
After looking at perf for the suggested methods for my use case they were very close, all within 0.5% of eachother, but the accepted answer, the objects.emplace_back() method was the most efficient.