InterfaceFileForASetTemplateClass
嗨 stackoverflow.com 论坛的人,我直接从教科书 Absolute C++ 第四版 Savitch ISBN-13:978-0-13-136584-1 中输入了这段代码。
设置模板类的接口文件第 808 页。
sort.cpp
在第 782 页上给出了第 13 行的错误:
Line 13 error: expected initializer before numeric constant
有人可以帮忙吗,因为我希望教科书“正常工作”,这样我就可以研究代码,而不会陷入我不理解的额外错误。
//This is the implementation file listtools.cpp. This file contains
//function definitions for the functions declared in listtools.h.
#include <cstddef>
#include "listtools.h"
namespace LinkedListSavitch
{
template<class T>
void headInsert(Node<T>*& head, const T& theData)
{
head = new Node<T>(theData, head);
}
template<class T>
void insert(Node<T>* afterMe, const T& theData)12
{
afterMe->setLink(new Node<T>(theData, afterMe->getLink()));
}
template<class T>
void deleteNode(Node<T>* before)
{
Node<T> *discard;
discard = before->getLink();
before->setLink(discard->getLink());
delete discard;
}
template<class T>
void deleteFirstNode(Node<T>*& head)
{
Node<T> *discard;
discard = head;
head = head->getLink();
delete discard;
}
//Uses cstddef:
template<class T>
Node<T>* search(Node<T>* head, const T& target)
{
Node<T>* here = head;
if (here == NULL) //if empty list
{
return NULL;
}
else
{
while (here->getData() != target && here->getLink() != NULL)
here = here->getLink();
if (here->getData() == target)
return here;
else
return NULL;
}
}
}//LinkedListSavitch