problem with delete
-
What's wrong with this piece of code? The destructor of Class Value is never been called! If I try to set a breakpoint there, the compiler immediately disables it. What am I doing here that's against the rules?
.h file
class Value
{
public:
unsigned char *pvalue;Value(int size)
{
pvalue=new unsigned char(size);
}
~Value()
{
delete [] pvalue; <-- No break point here
}
};class Parameter
{
public:
CString Name;
CString MenuItem;
void *pValue;
void *ValueText;
Parameter *next;
Parameter()
{
pValue = NULL;
next = NULL;
}
~Parameter()
{
if(pValue)
delete pValue;
}
};.cpp file
Parameter* Parm = new Parameter();
Parm->pValue = new Value(4);
delete Parm;Thanks, Arjan
-
What's wrong with this piece of code? The destructor of Class Value is never been called! If I try to set a breakpoint there, the compiler immediately disables it. What am I doing here that's against the rules?
.h file
class Value
{
public:
unsigned char *pvalue;Value(int size)
{
pvalue=new unsigned char(size);
}
~Value()
{
delete [] pvalue; <-- No break point here
}
};class Parameter
{
public:
CString Name;
CString MenuItem;
void *pValue;
void *ValueText;
Parameter *next;
Parameter()
{
pValue = NULL;
next = NULL;
}
~Parameter()
{
if(pValue)
delete pValue;
}
};.cpp file
Parameter* Parm = new Parameter();
Parm->pValue = new Value(4);
delete Parm;Thanks, Arjan
-
What's wrong with this piece of code? The destructor of Class Value is never been called! If I try to set a breakpoint there, the compiler immediately disables it. What am I doing here that's against the rules?
.h file
class Value
{
public:
unsigned char *pvalue;Value(int size)
{
pvalue=new unsigned char(size);
}
~Value()
{
delete [] pvalue; <-- No break point here
}
};class Parameter
{
public:
CString Name;
CString MenuItem;
void *pValue;
void *ValueText;
Parameter *next;
Parameter()
{
pValue = NULL;
next = NULL;
}
~Parameter()
{
if(pValue)
delete pValue;
}
};.cpp file
Parameter* Parm = new Parameter();
Parm->pValue = new Value(4);
delete Parm;Thanks, Arjan
You're probably confusing the debugger by having your implementation of ~Value() inside the class definition. split it up, put the definition in a .h file, and the implementation in a .cpp file. And it really is a sensible convention to start class name "C", ie "CValue". Sorry to dissapoint you all with my lack of a witty or poignant signature.