Thread: Why is destructor being called??

  1. #31
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Sorry about the last comment. I forgot to close to code tag
    Click on the edit button in the bottom right hand corner of the post and correct it.

  2. #32
    Registered User
    Join Date
    Jul 2005
    Posts
    64
    I FINALLY GOT IT!!! Turns out the problem was with the general constructor: I forgot to assign values for the individual data members (row, col, and empty). For some reason, after assigning the proper values, everything worked fine. In case you're curious, here is what I changed in the code (and good riddance to this problem once and for all):

    Code:
    Matrix::Matrix(const Matrix &another)
    {
    	row = another.row;
    	col = another.col;
    	if(!another.empty)
    	{
    		empty = false;
    		A = new Complex* [another.row];
    		for (int i=0; i<row; i++)
    			A[i] = new Complex[another.col];
    
    		for (i=0; i<row; i++)
    		{
    			for (int j=0; j<col; j++)
    			{
    				A[i][j] = another(i,j);
    			}
    		}
    	}
    	else
    		empty = true;
    }
    
    Matrix::Matrix(const int &a, const int &b)
    {
    	row = a;
    	col = b;
    
    	if(a==0 && b==0)
    	{
    		empty = true;
    	}
    
    	else
    	{
    		empty = false;
    		A = new Complex* [row];
    		for (int i=0; i<row; i++)
    			A[i] = new Complex[col];
    		
    		for (i=0; i<row; i++)
    		{
    			for(int j=0; j<col; j++)
    			{
    				A[i][j] = 0;		//zero-out the entire matrix;
    			}
    		}
    	}
    }
    By the way, thanks to all of you for helping me out. It was really helpful.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Destructor being called on SGI hash_map key
    By cunnus88 in forum C++ Programming
    Replies: 4
    Last Post: 02-11-2009, 12:05 AM
  2. Replies: 4
    Last Post: 09-21-2008, 02:27 PM
  3. callback from exe called with system()
    By leonv in forum C Programming
    Replies: 3
    Last Post: 01-25-2008, 04:12 PM
  4. AAARG!!! mental block, what is this character called: ')'
    By compjinx in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-29-2002, 10:29 PM
  5. Program ive been working on called ChatMate
    By dirkduck in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-23-2002, 09:05 PM