C++ memory heap questions.

This is a discussion on C++ memory heap questions. within the C++ Programming forums, part of the General Programming Boards category; lets say i have a class : Code: class ClassA { public: //some vars... HelpClass(void) { //some code... } }; ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,663
    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, 11:27 AM
  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, 04:03 AM

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