malloc in C++

Posted by Jason on Sun 27 Apr 2014 05:21 PM — 2 posts, 12,019 views.

#0
ok I am using a SWFOTEFUSS code base that compiles in C++ (which I am COMPLETELY NEW to C++), but I wanted to update my changes code from the basic that is with swfotefuss so I grabbed the snippet. When I try to compile I get these errors now:

  Compiling o/changes.o....
changes.c: In function `void load_changes()':
changes.c:86: invalid conversion from `void*' to `CHANGE_DATA*'
changes.c: In function `void delete_change(int)':
changes.c:144: invalid conversion from `void*' to `CHANGE_DATA*'
changes.c: In function `void do_addchange(CHAR_DATA*, const char*)':
changes.c:185: invalid conversion from `void*' to `CHANGE_DATA*'


Which the these are referring to malloc and realloc from c
To my understanding, C++ does not need these. So my question is how would I fix these:

From load changes

    changes_table = malloc( sizeof (CHANGE_DATA) * (maxChanges+1) );<--------This line
         for( i = 0; i < maxChanges; i++ )
    {
        changes_table.change = fread_string( fp );
        changes_table.coder = fread_string( fp );
        changes_table.date = fread_string( fp );
        changes_table.mudtime = fread_number( fp );
    }


From delete change:

    new_table = malloc( sizeof( CHANGE_DATA ) * maxChanges );<-----This line

    if( !new_table )
    {
       return;
    }
    


From do_addchange

    new_table = realloc( changes_table, sizeof( CHANGE_DATA ) *(maxChanges+1) );<-----This Line

    if (!new_table) /* realloc failed */
    {
        send_to_char ("Memory allocation failed. Brace for impact.\n\r",ch);
        return;
    }


Any help would be great... I'm still learning so please bare with me.
Amended on Sun 27 Apr 2014 05:29 PM by Jason
#1
Nevermind.... I got it... I'm a moron....