- #1
Rick21383
- 31
- 37
Could someone tell me what it wrong with this code? It seems to be identical to the code in a book I'm using but I get the error message with the line I've colored red:
error C2440: '=' : cannot convert from 'void *' to 'struct main::node *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
int main()
{
struct node{
int data;
struct node *nextPtr;
};
struct node newPtr;
newPtr = malloc( sizeof( struct node ) );
return 0;
}
edit:After including <stdlib.h> which I realized I need for the memory allocation, I get a new error message:
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'void *' (or there is no acceptable conversion)
I'm using Visual C++ 6.0 if that makes any difference
error C2440: '=' : cannot convert from 'void *' to 'struct main::node *'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
int main()
{
struct node{
int data;
struct node *nextPtr;
};
struct node newPtr;
newPtr = malloc( sizeof( struct node ) );
return 0;
}
edit:After including <stdlib.h> which I realized I need for the memory allocation, I get a new error message:
error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'void *' (or there is no acceptable conversion)
I'm using Visual C++ 6.0 if that makes any difference
Last edited: