Initializing Error

closed account (GvCfSL3A)
Alright so I'm new to C++ and have been programming in java before. I'm trying to get nodes to work but as I understand there is no garbage collection as there was in java. I'm having trouble with the malloc function and here's the code:
1
2
3
4
5
6
7
8
9
10
11
/*
*  newNode
*  Returns pointer to new Node struct. Initializes next field to NULL, and sets
*  data field to input parameter node_data. Private.
*/
NodeRef newNode(int node_data){
   NodeRef N = malloc(sizeof(Node));
   N->data = node_data;
   N->next = NULL;
   return(N);
}


And this is the error message: " error C2440: 'initializing' : cannot convert from 'void *' to 'NodeRef'".
What's causing this?
Last edited on
N needs to be a pointer to NodeRef.

malloc is a C programming technique. C++ uses the new operator - may be you should investigate that?

HTH
closed account (GvCfSL3A)
I see,
Thanks I'll look into it and re-post here if I run into problems.
Topic archived. No new replies allowed.