I\'m trying to implement a generic linked list. The struct for the node is as follows -
typedef struct node{
void *data;
node *next;
};
A void pointer cannot be dereferenced. You need to cast it to a suitable non-void pointer type. The question is about C++ so I suggest considering using templates to achieve your goal:
template struct node
{
T *data;
node *next;
};
then:
int n1=6;
node *temp = new node();
temp->data=&n1;
And finally:
cout << (*(temp->data));
Typecasting is possible, but that will be a C-style type-unsafe solution and not a C++ one.