weird compiler error---HELP!

S

sarah

I keep getting the following error:
g++ SortedList.cpp
SortedList.cpp:260: error: expected constructor, destructor, or type
conversion before '*' token
SortedList.cpp:260: error: expected `,' or `;' before '*' token
Line # 260 is ListNode *SortedList::copyList( ListNode *L ) {
towards the end of the .cpp file.

I have just put stubs in fr the code that I know works for readability
purposes. here is my code:
#ifndef SORTEDLIST_H
#define SORTEDLIST_H

#include "Student.h"


class SortedList {

public:

SortedList();
// Constructs an empty list.

SortedList(const SortedList &SL);
//Copy Constructor

~SortedList();
//Destructor

SortedList & operator=(const SortedList &SL);
//operator equals

bool insert(Student *s);
Student *find(int studentID);
Student *remove(int studentID);
void print() const;

private:

struct ListNode {
Student *student;
ListNode *next;
};

ListNode *head; // pointer to first node in the list

static void freeList(ListNode *L);
static ListNode *copyList(ListNode *L);
};

#endif

----------------------------------------------------------

SortedList.cpp
----------------------------------------------------

#include <iostream>
#include "Student.h"
#include "SortedList.h"

using namespace std;

/* Constructs an empty list
*/
SortedList::SortedList() {
head = NULL;
}

SortedList::SortedList(const SortedList &SL) {
}

SortedList::~SortedList() {
}

SortedList & SortedList::eek:perator=(const SortedList &SL) {
}


bool SortedList::insert(Student *s) {
}


Student *SortedList::find(int studentID) {
}


Student *SortedList::remove(int studentID) {
}


void SortedList::print() const {
}


void SortedList::freeList(ListNode *L) {
}


ListNode *SortedList::copyList( ListNode *L ) {
//create the node that is being copied to
ListNode *toReturn = new ListNode();

//if this is the last node in list, copy and return
if( L->next == NULL ) {
toReturn->student = new Student( L->next );

//else call the copy on the child of this node and
//copy the student to the linked list
} else {
toReturn->next = copyList( L->next );
toReturn->student = new Student( L->student );
}

return toReturn;
}
 
V

Victor Bazarov

sarah said:
I keep getting the following error:
g++ SortedList.cpp
SortedList.cpp:260: error: expected constructor, destructor, or type
conversion before '*' token
SortedList.cpp:260: error: expected `,' or `;' before '*' token
Line # 260 is ListNode *SortedList::copyList( ListNode *L ) {
towards the end of the .cpp file.

I have just put stubs in fr the code that I know works for readability
purposes. here is my code:
[...]
ListNode *SortedList::copyList( ListNode *L ) {

You need to qualify the 'ListNode' at the beginning:

SortedList::ListNode *SortedList ...

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top