1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| static void ITEM_constructor(ITEM* pThis, int id, char const *category, char const *name, float price)
{
pThis->id = id;
pThis->name = strdup(name);
pThis->category = strdup(category);
pThis->price = price;
}
ITEM * ITEM_new(int id, char const *category, char const *name, float price)//construit un item
{
ITEM *pThis = malloc(sizeof *pThis);
if(pThis != NULL)
{
ITEM_constructor(pThis, id, category, name, price);
}
return pThis;
}
static void ITEM_destructor(ITEM* pThis)
{
free(pThis->name), pThis->name=NULL;
free(pThis->category), pThis->category=NULL;
}
void ITEM_delete(ITEM* pThis)
{
if(pThis != NULL)
{
ITEM_destructor(pThis);
free(pThis);
}
} |
Partager