InterfaceFileForASetTemplateClass

InterfaceFileForASetTemplateClass

本文关键字:InterfaceFileForASetTemplateClass      更新时间:2023-10-16

InterfaceFileForASetTemplateClass

嗨 stackoverflow.com 论坛的人,我直接从教科书中输入了这段代码,绝对C++第四版萨维奇 ISBN-13:978-0-13-136584-1。

A 集模板类的接口文件页 808。

第 782 页上的sort.cpp给出了第 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

第 13 行有一个12,这真的在书上吗?如果是的话,这是一个严重的疏忽。只需删除它,您的代码就可以工作。

相关文章:
  • 没有找到相关文章