MALLOC

hi.. i am posting this thread because i hoping that somebody can help me about my problem. this freakn me out. i checked the code well and i got this 1 irritating error that i can't fixed out.

my code is this

newPtr = malloc(sizeof(ListNode));

where ListNode is my alias of my strcut definition i had declare earlier.
what is the problem that my compiler says "cannot convert void * to listnode *".. what is the problem with my code?

#thanks i hope you can help
closed account (3qX21hU5)
First and foremost this is a thread for the beginners section not the lounge.

That said if you are programming in C++ you should be using new/delete instead of malloc/free. Though if you do want to use malloc you have to remember that malloc returns a void pointer but you can cast that pointer to your desired type. In C you don't need to do this casting but C++ is a Strongly Typed Language so you need to do a explicit cast to tell the compiler that this is actually what you want to do because it won't implicitly do it for you.

I would suggest moving this thread to the beginners section and then maybe providing more of your code so we can be sure where your problem is.
Last edited on
Topic archived. No new replies allowed.