簡體   English   中英

HW 5 Rational pt2.exe 中 0x5E10F1C0 (ucrtbased.dll) 處未處理的異常:0xC0000005:訪問沖突讀取位置 0xCCCCCCCC。 發生了

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM