Pat Murray
Pat Murray

Reputation: 4285

Debugging Help: C++ error

I am getting this error:

SortedList.cpp:197: error: expected constructor, destructor, or type conversion before '*' token

This is the code:

197    Listnode *SortedList::copyList(Listnode *L) {
198        Listnode *current = L;
199
200        Listnode *copy = new Listnode;
201        copy->student = new Student(*current->student);
202        copy->next = NULL;
203
204        Listnode *head = copy;
205
206        current = current->next;
207        while (current != NULL) {
208            copy = copy->next = new Listnode;
209            copy->student = new Student(*current->student);
210            copy->next = NULL;
211        }
212        return head;
213    }

This is the Listnode:

struct Listnode {
    Student *student;
    Listnode *next;
};
Listnode *head;

Not sure what I am supposed to do. I have a constructor and destructor implemented already if needed to be viewed. Any insight as to what the problem possibly is would be helpful.

Upvotes: 0

Views: 97

Answers (1)

keety
keety

Reputation: 17461

From the comments ListNode appears to be a nested class you need to use the following : SortedList::Listnode *SortedList::copyList(SortedList::Listnode *L) also you may need to make it public if copyList is public.

Upvotes: 2

Related Questions