Suppose I have the following code.
vector<Cat> v; \\Cat is a class
for (int i = 0; i < 5; i++)
{
Cat cat1;
if (someFunction(i))
{
cat1.setName("Whiskers");
v.push_back(whiskers) ;
}
}
My question is, in a for loop, does the object cat1 go out of scope while executing 0 to 4
? That is will the destructor get called 5 times here or just once?