2

I am having some issues with code that is returning a pointer to a struct declared inside a class. Here is my code so far:

SortedList.h

#ifndef SORTEDLIST_H
#define SORTEDLIST_H

class SortedList{

 public:

    SortedList();

 ...

 private:

    struct Listnode {    

      Student *student;

      Listnode *next;

    };

    static Listnode *copyList (Listnode *L);

};

#endif

SortedList.cpp

#include "SortedList.h"

...

// Here is where the problem lies

Listnode SortedList::*copyList(Listnode *L)

{

    return 0; // for NULL

}

Apparently, the copy list method wont compile. I am using Microsoft Visual Studio and the compiler tells me that "Listnode" is unidentified. When I try to compile, here is whhat I get:

1>------ Build started: Project: Program3, Configuration: Debug Win32 ------

1>  SortedList.cpp

sortedlist.cpp(159): error C2657: 'SortedList::*' found at the start of a statement (did you forget to specify a type?)

sortedlist.cpp(159): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

sortedlist.cpp(159): error C2065: 'L' : undeclared identifier

sortedlist.cpp(159): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

sortedlist.cpp(159): fatal error C1903: unable to recover from previous error(s); stopping compilation

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Help would be greatly appreciated...ASAP

1

1 Answer 1

2

Inside the cpp file, the function should be defined as:

SortedList::Listnode* SortedList::copyList(ListNode* L)
{
    return 0; //For NULL
}

Also, the struct Listnode should be declared either public or outside the class SortedList.

Sign up to request clarification or add additional context in comments.

1 Comment

Note that inside the parentheses, you don't need the SortedList:: because at that point you are inside a SortedList function so you are in its scope, which means that Listnode is in scope.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.