[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RTEMS/GCC C++ delete structure that contains a class
- Date: Tue, 18 Sep 2007 12:01:07 -0600
- From: brett.swimley at aedbozeman.com (Brett Swimley)
- Subject: RTEMS/GCC C++ delete structure that contains a class
Hi All,
I may be violating "best practice" coding, but I have a question
regarding the RTEMS delete operator.
Consider something like:
class foo
{
public:
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;
} FOO_INFO;
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
destructor?
Thanks in advance.
Brett