程序崩溃了,显示DAMAGE after Normal block (#43) at……
我写了个类,才刚写一点,出现了点问题:每次运行的时候程序都会崩溃,我逐行测试后发现是在测试代码的最后一句return 1; 后崩溃的
因为用无参数构造函数就不会崩溃,我感觉是析构函数出现了问题,麻烦大家帮我看看
程序代码:/*
* 无参数构造函数
*/
Formula::Formula(void)
{
formulaString = new char [1];
formulaString = '\0';
return;
}
程序代码:/*
* 有参数构造函数
*/
Formula::Formula(const char * str)
{
if (str == NULL)
{
formulaString = new char [1];
formulaString = '\0';
}
else
{
formulaString = new char [strlen(str)];
strcpy(formulaString,str);
}
return;
}
程序代码:/*
* 析构函数
*/
Formula::~Formula(void)
{
delete [] formulaString;
return;
}这是声明,就一个成员变量
程序代码:class Formula
{
public:
Formula(void);
Formula(const Formula & f);
Formula(const char * str);
Formula(const double num);
~Formula(void);
public:
Formula & operator = (const char * str);
Formula & operator = (const Formula & f);
Formula & operator = (const double num);
public:
int GetLength (void) const;
public:
void Trim (void);
private:
char * formulaString;
};这是测试代码
程序代码:int main (void)
{
Formula f(" vfjwjfwe");
// f.Trim ();
return 1;
}








