SO, I'm trying to write a generic singly linked list implementation that works with all types, and keep coming across the error of: Assignment from incompatible pointer type for the line of code that is as follows:
node->next = newNode;
This is in the context of the following declarations and structs:
typedef struct{
void* data; // The generic pointer to the data in the node.
Node* next; // A pointer to the next Node in the list.
} Node;
void insertAfter(Node* node, Node* newNode){
// We first want to reassign the target of node to newNode
newNode->next = node->next;
// Then assign the target of node to point to newNode
node->next = newNode;
}
I have tried to use both this: node->next = *newNode; and this: node->next = &newNode; But as you can imagine, they do not work, what am I doing wrong here, what and why is this error being caused and how do I fix it?
Nodeinside that typedef-struct definition for typeNode. This will immediately trigger a compile error. Either you have another definition for some other typeNodesomewhere, or the code you posted is not the code you compiled. And if you really had another typeNodedeclared somewhere you'd typically get a compile error for type redefinition. So, I'd guess that the code you posted is inaccurate.