InterfaceFileForASetTemplateClass

Hi cplusplus.com forum people,
I've typed up this code direct from the text book, Absolute C++ Fourth Edition Savitch ISBN-13: 978-0-13-136584-1.
Interface File For A Set Template Class page 808.
sort.cpp on page 782 gives the error on line 13:
Line 13 error: expected initializer before numeric constant

Could someone help as I would expect the text book to 'just work' so I can study the code and not get stuck on extra errors I don't understand.

I bolded line 13 where the error occurs.


//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
closed account (o3hC5Di1)
Hi there,

void insert(Node<T>* afterMe, const T& theData)12

That 12 is causing the error I believe.
It's probably a typo, but the compiler is saying "hey, you're throwing some numerical data into the program without telling me about it" i.e. without declaring/initializing it.

Also, next time you post code, please put it in a code block (see '<>' bottom / right of the editor) so your code will be a bit more readable to us. :)

Hope that helps,
All the best,
NwN
Last edited on
Topic archived. No new replies allowed.