编写扩展LinkedList的对象

时间:2016-09-13 23:02:11

标签: c++

我的代码存在问题,我将尝试将其简化为概念性问题。

我有一个名为Declare @YourTable table (mis int,mnth varchar(25),IPTV decimal(18,9)) Insert Into @YourTable values (0,'January',0.2026856),(0,'February',0.4860267),(0,'March',0.2650674),(0,'April', 0.1904701),(1,'January',0.266809),(1,'February',0.310241),(1,'March', 0.2083876),(1,'April', 0.3401039),(2,'January',0.307787),(2,'February',0.5276488),(2,'March',0.3037852),(2,'April',0.1822988),(3,'January',0.8107423),(3,'February',0.2430134),(3,'March',0.1988006),(3,'April',0.2539602) --below is the solution select *,sum(iptv)over(partition by mnth order by mis) as Wanted from @yourtable 的班级,它是PunctuationOccurrenceList的{​​{1}}。 LinkedList只是一个没有任何指针的数据类。

PunctuationOccurrence的析构函数如下:

PunctuationOccurrence

LinkedListtemplate <class Object> LinkedList<Object>::~LinkedList() { /* Here, you could just delete the headerNode, since everything else is linked to it (the point of a LinkedList!!), and will * also be deleted!! */ if (this->headerNode) delete this->headerNode; this->lastNode = 0; } 个具有析构函数的内容:

LinkedList

我必须为ListNode编写复制构造函数。但是,当template <class Object> ListNode<Object>::~ListNode() { if (this->nextNode) delete this->nextNode; } 超出范围时,事情会变得奇怪。在测试PunctuationOccurrenceList模块时,它可以正常工作。但是,当用作另一个类的对象成员时,如果它不为空,则会发生分段错误。

我知道rule of three说我应该写复制构造函数。我该怎么写呢?

1 个答案:

答案 0 :(得分:2)

LinkedList的复制构造函数应该创建整个列表的副本;它应该复制原始列表中的每个节点。

相关问题