Consider the following definition for the node of a Linked List:
struct Node
{
int data;
struct Node *next;
};
I am new to c++ and coming from functional programming. I wish to write a lambda to compute the length of a linked list. I wrote:
auto listLength = [](Node * list){
if(list == NULL) return 0;
else return 1 + listLength(list -> next);
};
error: variable 'lengthList' declared with 'auto' type cannot appear in its own initializer
If I change from auto to int I get:
error: called object type 'int' is not a function or function pointer
What is the issue?