Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Destructor in linklist and constructor for linklist
Posted

1 solution

You probably could have asked this in the same question as your previous one.
If you make each node in the linked list a class, it will just work. Just be sure to use new to create each node and delete to delete them.

C++
class A {
	public:
		A() {
			//This is the default constructor for class A
			//Initialise any variables in here
			m_pNext = NULL;
		}
		A(A *next) {
			//This is a constructor for class A which takes an integer variable
			//Initialise any variables in here
			m_pNext = next;
		}
		~A() {
			//This is the one and only destructor for class A
			//cleanup and allocated memory and such in here
		}
	private:
		A *m_pNext; //some random variable to show constructors
};
 
Share this answer
 
Comments
Member 8370427 10-Nov-11 8:33am    
you are good programmer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900