Okay, so I've been kind of putting off learning linked lists for a couple of days because I hate learning things that I don't completely understand... but I finally decided to just jump in and go with it.
I am following a tutorial from Stanford's Computer Science department and have basically copied the tutorial code (except changed 'head' to 'root', just to be different :))
#include <iostream>
using namespace std;
struct node {
int data;
struct node* next;
};
struct node* buildNodes() {
struct node* root = NULL;
struct node* second = NULL;
struct node* third = NULL;
//allocate three nodes in the heap
root = malloc(sizeof(struct node));
second = malloc(sizeof(struct node));
third = malloc(sizeof(struct node));
root->data = 1;
root->next = second;
root->data = 2;
root->next = third;
root->data = 3;
root->next = NULL;
return root;
}
int main() {
}
Okay, I'm starting to understand this a little more... except I have no idea why my compiler (Bloodshed's Dev-C++) gives me the error "invalid conversion from 'void*' to 'node*'." (it points to the lines using the malloc() function).
hmm.... I could have sworn
struct node* root = NULL;
would make 'root' the type 'node'. I really have very little clue about what I'm saying... heh
Question
generalt
Okay, so I've been kind of putting off learning linked lists for a couple of days because I hate learning things that I don't completely understand... but I finally decided to just jump in and go with it.
I am following a tutorial from Stanford's Computer Science department and have basically copied the tutorial code (except changed 'head' to 'root', just to be different :))
Okay, I'm starting to understand this a little more... except I have no idea why my compiler (Bloodshed's Dev-C++) gives me the error "invalid conversion from 'void*' to 'node*'." (it points to the lines using the malloc() function).
hmm.... I could have sworn
would make 'root' the type 'node'. I really have very little clue about what I'm saying... heh
any ideas?
Link to comment
https://www.neowin.net/forum/topic/597886-c-linked-lists-invalid-conversion-from-void-to-node/Share on other sites
5 answers to this question
Recommended Posts