Thread: _BLOCK_TYPE_IS_VALID(phead->nBlockUse)

  1. #1
    edwardtisdale
    Guest

    Cool _BLOCK_TYPE_IS_VALID(phead->nBlockUse)

    Debug Assertion Failed. directly after exiting a member function (as I saw with step-into), happening I think in this part of my code:
    drinksAtWork::drinksAtWork()
    {
    ch=new char;
    ch="ff";

    }
    drinksAtWork::~drinksAtWork()
    {
    delete ch;
    //error happens right here, which is called upon leaving main().}

    The ch is a private char pointer in the drinksAtWork class.

    There is only one member function which has only cout and cin.

    What is wrong?

    www.edwardtisdale.com

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    ch=new char;

    allocates space for one char on the heap and returns the address in ch.

    ch="ff";

    points ch at a string literal. It no longers points to the memory on the heap and you're then trying to delete memory that you haven't allocated. You could do something like

    ch=new char[3]; // for 'f','f','\0'
    strcpy(ch,"ff");

    and then

    delete [] ch;
    zen

Popular pages Recent additions subscribe to a feed