C++中关于new的问题。。。。。。。。。。。。

来源:百度知道 编辑:UC知道 时间:2024/05/14 07:11:12
我的程序能够编译正确,但是在执行的时候谈出一个对话框,提示程序不能正确执行,通过调试大限问题出现在new上,它执行下面的一句代码时出现了问题:
new_node = new ListNode<ListNodeEntry> (x,following);
其中new_node定义如下:
ListNode<ListNodeEntry> *new_node;
其中ListNode定义如下:
template <class ListNodeEntry>
struct ListNode
{
ListNodeEntry data;
ListNode<ListNodeEntry> *next;
ListNode();
ListNode(ListNodeEntry item, ListNode <ListNodeEntry> *add_on=NULL);
};
以上代码是一个链接表中的,链接表是一个模版类,程序中应用时声明对象如下:
List<HuffmanNode> m_lstLittleHuffList;

这里的HuffmanNode是一个结构体,具体如下:

struct HuffmanNode
{
char InfoSign;
int InfoSignCount;
String CodingValue;
HuffmanNode();
HuffmanNode(int infosigncount);
HuffmanNode(char &infosign, int &infosigncount);
HuffmanNode(HuffmanNode &stCopy);
friend bool operator == (const HuffmanNode &first, const HuffmanNode &second);
friend bool operator > (const Hu

从你上面可以看出,似乎ListNodeEntry是一个模板变量,那么语句
ListNode<ListNodeEntry> *new_node;
new_node = new ListNode<ListNodeEntry> (x,following);
就不正确了,看样子应该是
ListNode<HuffmanNode> *new_node;
new_node = new ListNode<HuffmanNode> (x,following);