_BLOCK_TYPE_IS_VALID(phead->nBlockUse)

This is a discussion on _BLOCK_TYPE_IS_VALID(phead->nBlockUse) within the C++ Programming forums, part of the General Programming Boards category; Debug Assertion Failed. directly after exiting a member function (as I saw with step-into), happening I think in this part ...

  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
    zen
    zen is offline
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21