destructor/stack
Jul 30, 2016 at 5:27pm UTC
Hi,
I want to destroy every constructor I have made (10). I don't know how to do this or if this can be done. I'd like control over the destruction process item by item.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#include<iostream>
using namespace std;
class Stack
{
public :
Stack(int stackNum)
{
cout<<stackNum<<" constructed" <<endl;
}
};
int main()
{
//create stack
for (int i = 0; i<10; ++i)
{
Stack stack(i); // create constructor
}
/*code here
return 0;
}
*/
Jul 30, 2016 at 6:20pm UTC
As the loop iterates, you create a single Stack object each iteration which is immediately destroyed.
By the time you reach line 21, there are no Stack objects in existence.
Topic archived. No new replies allowed.