I'm trying to create an array of classed dynamically, where constructs and destructs are called automatically. This code that I wrote test this thing, but I get memory leaks. How it's possible? I'm deleting every class that I created previously and I delete also the array that holds the classes pointers. In C# it works without problems.
There is the code:
int count;
class Test
{
public:
int var;
Test()
{
var = count++;
printf("Test() %i\n", var);
}
~Test()
{
printf("~Test() %i\n", var);
}
};
int main()
{
count = 0;
Test *test;
while(1)
{
test = new Test[10];
for(int i=0; i<10; i++)
delete &test;
delete test;
}
}