RTEMS/GCC C++ delete structure that contains a class

Brett Swimley brett.swimley at aedbozeman.com
Tue Sep 18 18:01:07 UTC 2007

Hi All,

I may be violating "best practice" coding, but I have a question 
regarding the RTEMS delete operator.

Consider something like:

class foo
 foo() { p = new unsigned char[10]; }
virtual ~foo() { delete[] p; }
unsigned char* p;

I understand that calling new in a class constructor may not be the best 
coding practice, but...

Now consider a structure that contains the class:

typedef struct foo_info
foo fooinfo;
int i;

Now, given this code...

q = new FOO_INFO;

q->i = 0;   // For example...

delete q;

It appears that the destructor for foo never gets called.  Tracing into 
the delete operator, it is just calling free.  

Is this normal behavior?  It appears that if I change my structure 
declaration into a class definition, the expected behavior occurs.  If 
this is what needs to be done, I certainly can do this.

Should deleting a structure that contains a class invoke the class 

Thanks in advance.


More information about the users mailing list