Thread: plz help with deleting class deconstructor.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    47

    plz help with deleting class deconstructor.

    **just realized my topic title makes no sense.. apologize ahead of time.

    I'm having a hard time with this code.. plz help me out..


    Code:
    #include<iostream>
    using namespace std;
    
    char input[101];
    
    class NameAdd
    {
    	char* name;
    	char* address;
    
    	public:
    		NameAdd()	{
    				this->name = "my_name";
    				this->address = "my_address";
    		}
    		~NameAdd()	
    		{	
    			cout << "Deleting the base!!!" << endl;
    			delete this->name; delete this->address;
    		}
    };
    
    class amountnum : virtual public NameAdd
    {
    	char* amount;
    
    	public:
    		amountnum()	
    		{		
    				this->amount = "a_amount";
    		}
    		~amountnum()	
    		{
    			cout << "Deleting the osap!!!" << endl;
    			delete this->amount;
    		}
    };
    
    
    int main()
    {
    	NameAdd * formlist[5];
    	int limit = 1;
    	formlist[limit] = new amountnum();
    	system("pause");
    	delete formlist[limit];
    	cout << "success!" <<endl;
    	system("pause");
            return 0;
    }
    i know the delete isn't working. i was hoping someone could shine some light as to whats wrong.
    Last edited by MegaManZZ; 08-31-2008 at 09:16 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inherite nonvirtual class functionality
    By DrSnuggles in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2009, 01:52 PM
  2. class composition constructor question...
    By andrea72 in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2008, 05:11 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM