weird compiler error---HELP!

Discussion in 'C++' started by sarah, Nov 3, 2005.

  1. sarah

    sarah Guest

    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;
    }
     
    sarah, Nov 3, 2005
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Nov 3, 2005
    #2
    1. Advertising

  3. sarah

    sarah Guest

    many thanks!!
     
    sarah, Nov 3, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yan
    Replies:
    0
    Views:
    1,175
  2. neverstill

    weird compiler error

    neverstill, Jan 6, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    338
    neverstill
    Jan 6, 2004
  3. Ram
    Replies:
    0
    Views:
    2,940
  4. dorayme
    Replies:
    1
    Views:
    657
    richard
    Jan 21, 2011
  5. richard
    Replies:
    0
    Views:
    617
    richard
    Jan 21, 2011
Loading...

Share This Page