undeclared identifier

I am trying to write a getFirst function within a linked list code that will return a pointer to the first object in the list however I am getting an undeclared identifier when trying to use a variable I have used previously and am unsure why it does not work in my new code.

error: use of undeclared identifier 'start'
return *start;


function that produces error
1
2
3
  Node* getFirst(){
      return start;
  }

constructor for the linked list
1
2
3
4
5
LinkedList::LinkedList() {
	start = 0;
	last = 0;
	count = 0;
} 

hpp file implementation
1
2
3
4
5
class LinkedList {
private:
	Node *start;
public:
	Node* getFirst();};

Last edited on
You need to specify the class when defining the function, otherwise the compiler will think you are trying to create a global function that is not part of any class.

1
2
3
Node* LinkedList::getFirst(){
	return start;
}
Topic archived. No new replies allowed.