I am trying to write a linked list class with some basic features like add node, delete a node and search recursively in the list. I have defined the head of the list as a private variable but I need to access it for the recursive search function so I tried to define a GetHead() function that will return the pointer to head. However I am having some trouble with compiling it in NetBeans.
Here is the class header
class List{
private:
typedef struct node{
int data;
node* next;
}*nodePtr;
nodePtr head;
nodePtr curr;
nodePtr temp;
public:
List();
void AddNode(int addData);
void DelNode(int delData);
void PrintList();
void SearchRecursive(nodePtr Ptr, int searchVal);
nodePtr GetHead();
};
The GetHead() function is as follows:
nodePtr List::GetHead(){
return head;
}
When I compile, I get
error: unknown type name 'nodePtr'
error: cannot initialize return object of type 'int'
with an lvalue of type 'nodePtr' (aka 'List::node *')
Is there a problem in how I am returning the pointer to the struct node?
nodePtr GetHead();This won't work forpublicaccess scope, sincenodePtris declared in theprivateclass section.auto. As long as you don't name the private thing...auto.