Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

CStringArray unable to properly delete itself

BriballBriball Posts: 265Member
It seems that on many occasions CStrings in a CStringArray have given me trouble. They constantly have access violations, and the error claims that scalar destructor delete...something. Anyone know what the hell is going on.

Sorry but there is no real code to show. It is simply a CStringArray is a member of a class, and when the class is destroyed...

Comments

  • stoberstober Posts: 9,765Member ✭✭✭
    : It seems that on many occasions CStrings in a CStringArray have given me trouble. They constantly have access violations, and the error claims that scalar destructor delete...something. Anyone know what the hell is going on.
    :
    : Sorry but there is no real code to show. It is simply a CStringArray is a member of a class, and when the class is destroyed...
    :
    [blue]It will do that if you attempt to access a non-existent element (beyone the end of the array) ot add a new element when the array isn't big enough. Read about the different methods carefully, many of them do not automatically expand the array.[/blue]
    [code]
    void CTestDlg::OnOK()
    {
    CStringArray ay;
    CString str;
    ay.Add("One"); // ok
    ay.Add("Two"); // ok
    ay[3] = "Three"; // error because the array only has 2 elements
    for(int i = 0; i < 3; i++)
    {
    str = ay[i];// error when i = 2
    }
    CDialog::OnOK();
    }
    [/code]
Sign In or Register to comment.