Good morning,
I have a task to create a certain amount of objects. However, an object has a variable called age. Once that variable reaches 10 it should be deleted. Is it possible? If it is how could i do that?
#include <iostream>
int main()
{
int *pAge = newint;
std::cout << "age created.\n\n";
int &age = *pAge;
age = 0;
while (true)
{
std::cout << age << ' ' << std::flush;
if (++age == 10)
{
delete pAge;
std::cout << "\n\nage deleted.\n";
break;
}
}
return 0;
}
Note, the above frees the memory being used. Meaning other things are allowed to use that memory. But it will exist until something else starts using it.