cannot convert from 'void *' to 'node *'

This is a discussion on cannot convert from 'void *' to 'node *' within the C Programming forums, part of the General Programming Boards category; Every time I try to compile my program i get the error: error C2440: 'initializing' : cannot convert from 'void ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    4

    cannot convert from 'void *' to 'node *'

    Every time I try to compile my program i get the error: error C2440: 'initializing' : cannot convert from 'void *' to 'node *'
    To be honest I dont understand the error and i have changed the line a few times to fix it but to no avail

    The code containing the line and the struct declarisation is below:

    Code:
    #include <stdio.h>
    #include <stdlib.h> 
     
    struct node
    {
    	int data;
    	struct node *next;
    };
     
    struct node *CTaxi_addTaxi(struct node **p, int i)
    {
    	struct node *n = malloc(sizeof(struct node)); //ERROR ON THIS LINE!
    	if (n == NULL)
    		return NULL;
     
    	n->next = *p;
    	*p = n; 
    	n->data = i;
     
    	return *p;
    }
    Thanks for any help given

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,594
    You are comping the code as C++, so either:
    1) Add a cast: struct node* n = (struct node*)malloc(sizeof(struct node)); //ERROR ON THIS LINE!
    2) Compile as C.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to better manage large .cpp files
    By 39ster in forum C++ Programming
    Replies: 6
    Last Post: 08-25-2008, 08:24 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. help me debug this linked list !
    By Dark Angel in forum C Programming
    Replies: 6
    Last Post: 04-18-2008, 02:10 PM
  4. question about a working linked list
    By cold_dog in forum C++ Programming
    Replies: 23
    Last Post: 09-13-2006, 01:00 AM
  5. msvc just ate one of my source files
    By Eber Kain in forum C++ Programming
    Replies: 6
    Last Post: 07-01-2004, 05:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21