C ++析构函数功能 [英] C++ Destructors functionality

查看:89
本文介绍了C ++析构函数功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

链接列表中的析构函数和链接列表的构造函数

Destructor in linklist and constructor for linklist

推荐答案

您可能已经在与上一个问题相同的问题中提出了这个问题. 如果将链接列表中的每个节点都设为一个类,则它将正常工作.只需确保使用new创建每个节点,并使用delete删除它们.

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.

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
};


这篇关于C ++析构函数功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆