【发布时间】:2017-10-17 04:30:00
【问题描述】:
我很困惑为什么会收到此错误。我环顾四周,发现有人有类似的错误,他们的问题是没有为 NULL 分配足够的新内存。我不认为这是我的问题,因为我添加了 strlen + 1?我迷路了……
//Copy Constructor
Rational::Rational(const Rational& other) :
m_numerator(other.m_numerator), m_denominator(other.m_denominator),
m_name(NULL)
{
m_name = NULL;
if (other.m_name != NULL)
{
this->m_name = new char[strlen(other.m_name) + 1]; //ErrorMarkHere
strcpy(this->m_name, other.m_name);
}
}
【问题讨论】:
-
0xCC 表示您已阅读uninitialized memory
-
读取错误,而不是写入错误...
other.m_name不是 NULL,但它实际上是一个正确终止的字符串吗?