Thread: he we go again

  1. #31
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    It would be interesting to comment the delete within the destructor, and see what happens:
    Code:
    asset::~asset()
    {	//delete [] name; }

  2. #32
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    In principle, the compiler should hit an "Unexpected end of file" error. But anyway, that line should be fine, as should something like this:
    Code:
    #include <iostream>
    int main() {
       char* str = NULL;
       delete[] str;
       std::cout << "Deletion successful." << std::endl;
       return 0;
    }
    By the way, what compiler are you using, misplaced?
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  3. #33
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >In principle, the compiler should hit an "Unexpected end of file" error.
    Heh, let me try again:
    Code:
    asset::~asset()
    {
    	//delete [] name;
    }
    There's a mystery here which would be nice to solve. I've run it with both Dev-C++ and Borland. Is it the compiler, or some part of the classes Misplaced hasn't posted?

  4. #34
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Well, misplaced, can you run it through a debugger? It sure would be nice to know exactly what line in what function call that the thing crashes on (one of the destructors I assume).
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #35
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    Quote Originally Posted by swoopy
    >In principle, the compiler should hit an "Unexpected end of file" error.
    Heh, let me try again:
    Code:
    asset::~asset()
    {
    	//delete [] name;
    }
    There's a mystery here which would be nice to solve. I've run it with both Dev-C++ and Borland. Is it the compiler, or some part of the classes Misplaced hasn't posted?
    you solved the mystery.......
    delete [] name
    was causing it all along.......

    any ideas?
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  6. #36
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Invalid pointer value AKA seg fault, or deconstructed twice (has happened to me). To make a solid deconstructor do this:
    Code:
    asset::~asset(){
        if(name)
            delete [] name;
        name=0;
    }
    
    //And had this to the asset constructor
    asset::asset() : name(0) /*other constructors*/{
       // do the stuff you want
    }
    Last edited by xErath; 11-20-2004 at 01:25 AM.

  7. #37
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >any ideas?
    A bug in your compiler?

    Try these two things, and see if either or both work.
    (1)
    Code:
    asset::~asset()
    {
    	cout << "Asset ~asset()" << endl;
    	if (name != NULL)
    		delete [] name;
    }
    (2)
    Code:
    asset::~asset()
    {
    	cout << "Asset ~asset()" << endl;
    	delete name;
    }

  8. #38
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Can you post the whole thing in a zip? I'd like to run it through a debugger.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed