I'm curious to know how i would get around the static member error.
Code:
#include <stdlib.h>
struct image
{ short count;
unsigned int * num;
unsigned int ** nums;
void Init( short number )
{
num = NULL;
nums = NULL;
count = number;
if( number == 1)
num = (unsigned int *)malloc( sizeof(unsigned int));
else if ( number > 1 )
{
nums = (unsigned int **)malloc( sizeof(unsigned int) * number);
int i;
for( i = 0; i < count; ++i)
{
nums[count] = NULL;
}
}
}
void operator delete (void *p)
{
image * q = (image * )p;
if( q->count == 1 )
{ free(q->num); num = NULL ; }
else if( q->count > 1 )
{
int i = 0;
for( i = 0; i < q->count; ++i)
{
if( q->nums[q->count] != NULL )
free( q->nums[q->count] );
}
free( q->nums );
}
free(p);
p = NULL;
}
};
int main(void)
{
image * something;
something->Init( 1 );
delete something;
return 0;
}
I was trying to make a image struct to hold either 1 array of unsigned integers or an array of images. I wanted to push each structure into a class hash table I built a while back, but I had an issue using delete in my hash table and with the lost of memory from the array of unsigned int. So i thought about using a overloaded method for delete to avoid the problem, and not to reconstruct my hash table just around this one issue.