[英]Exception thrown at 0x50E6F1C0 (ucrtbased.dll) in CandidateVotes.exe: 0xC0000005: Access violation reading location 0x00000000
[英]Unhandled exception at 0x5E10F1C0 (ucrtbased.dll) in HW 5 Rational pt2.exe: 0xC0000005: Access violation reading location 0xCCCCCCCC. occurred
我很困惑為什么會收到此錯誤。 我環顧四周,發現有人有類似的錯誤,他們的問題是沒有為 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);
}
}
0xCCCCCCCC
表示某些編譯器未初始化的內存。 幾乎在那條線上唯一可能失敗的是strlen(other.m_name)
,其中other.m_name
可能是前面提到的指針。 other
是如何從墜毀的地方構建的?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.