0

I have the following structs:

struct mtmFlix_t {
    List usersList;
    List seriesList;
};

struct User_t {
    int age;
    char* username;
    MtmFlix mtmFlix;
};

These are the typedefs in list.h :

typedef void* ListElement;
typedef ListElement(*CopyListElement)(ListElement);
typedef void(*FreeListElement)(ListElement);

These are the typedefs in user.h and MtmFlix.h :

typedef struct User_t *User;
typedef struct mtmFlix_t* MtmFlix;

I would like to use the following function in mtmflixCreate, but I can't seem to figure out how to cast the UserCreate and UserFree to (*void) ?

List listCreate(CopyListElement copyElement, FreeListElement freeElement);

MtmFlix mtmFlixCreate()
{
    MtmFlix newMtmFlix = malloc(sizeof(*newMtmFlix));
    if (newMtmFlix == NULL) {
        return NULL;
    }
    newMtmFlix->seriesList=listCreate(?????);
    newMtmFlix->usersList=listCreate(?????);
}

The following functions appear in user.h :

User UserCreate(MtmFlix mtmFlix, const char* username,int age);
Void UserFree(User user);
Barmar
  • 741,623
  • 53
  • 500
  • 612
Sam12
  • 1,805
  • 2
  • 15
  • 23

1 Answers1

1

You don't. You have to create functions that have the needed types. Something like this:

ListElement CopyUserListElement(ListElement elem) {
    // (ListElement) is not necessary here, but included for completeness
    return (ListElement)CopyUser((User_t*)elem);
}

void FreeUserListElement(ListElement elem) {
    UserFree((User_t*)elem);
}
user253751
  • 57,427
  • 7
  • 48
  • 90