By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,513 Members | 1,689 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,513 IT Pros & Developers. It's quick & easy.

weird compiler error---HELP!

P: n/a
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::operator=(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;
}

Nov 3 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
sarah wrote:
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
Nov 3 '05 #2

P: n/a
many thanks!!

Nov 3 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.