Thread: C++ memory heap questions.

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    29

    C++ memory heap questions.

    lets say i have a class :
    Code:
    class ClassA
    {
    public:
    	//some vars...
    
    	HelpClass(void)
    	{
    		//some code...
    	}
    };
    And a class that needs the previous class :
    Code:
    class NeedsClassA
    {
    public:
    	ClassA* m_var;
    	//some vars...
    
    	NeedsClassA(void)
    	{
    		this->m_var = new ClassA();
    		//some code
    	}
    };
    and main...
    Code:
    int main()
    {
    	NeedsClassA* var = new NeedsClassA();
    	delete var;
    	return 0;
    }
    when i delete, will all the contents of the object be deleted or will var->m_var stay?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well put some cout statements inside the constructor and destructor functions of each class and find out.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    29
    haha, why didn't I think of that!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ memory questions
    By jcafaro10 in forum C++ Programming
    Replies: 2
    Last Post: 04-05-2009, 09:24 PM
  2. Replies: 7
    Last Post: 02-06-2009, 12:27 PM
  3. Segmentation fault!?!?!?
    By Viper187 in forum Windows Programming
    Replies: 57
    Last Post: 10-02-2008, 09:40 PM
  4. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  5. heap question
    By mackol in forum C Programming
    Replies: 1
    Last Post: 11-30-2002, 05:03 AM