xxxxxx

typedef struct

{

   int refs;       // reference count

   int count_1fen;

   int count_2fen;

   int count_5fen;

} bank_data_s_type

 

bank_data_s_type* PiggyBank_New( )

{

bank_data_s_type *pNew = MALLOC(sizeof(bank_data_s_type));

   if (pNew != NULL)

      MEMSET(pNew, 0x00, sizeof(bank_data_s_type));

   PiggyBank_AddRefs(pNew);

   return pNew;

}

 

static void PiggyBank_Free(bank_data_s_type **ppData)

{

   if (NULL == ppData)

      return;

   FREE(*ppData);

   *ppData = NULL;

}

 

int PiggyBank_AddRefs(bank_data_s_type *pData)

{

   return pData->refs++;

}

 

int PiggyBank_Release(bank_data_s_type *pData)

{

   if (--pData->refs > 0)

      return pData->refs;

   PiggyBank_Free(&pData);

   return 0;

}

 

void PiggyBank_Input(bank_data_s_type *pData, int type)

{

   … …

}

 

void PiggyBank_Output(bank_data_s_type *pData, int type)

{

   … …

}

 

int PiggyBank_GetTotal(bank_data_s_type *pData, int type)

{

  … …

}

 

///

 

enum

{

COIN_TYPE_NONE,

   COIN_TYPE_1FEN,

   COIN_TYPE_2FEN,

   COIN_TYPE_5FEN

};

 

typedef struct PiggyBank PiggyBank;

 

PiggyBank* PiggyBank_New( );

int PiggyBank_AddRefs(PiggyBank *pPiggyBank);

int PiggyBank_Release(PiggyBank *pPiggyBank);

void PiggyBank_Input(PiggyBank *pPiggyBank, int type);

void PiggyBank_Output(PiggyBank *pPiggyBank, int type);

int PiggyBank_GetTotal(PiggyBank *pPiggyBank, int type);

   

储蓄罐封装形式四:PiggyBank.c

struct PiggyBank

{

   int refs;       // reference count

   int count_1fen;

   int count_2fen;

   int count_5fen;

};

 

PiggyBank* PiggyBank_New( )

{

PiggyBank *pNew = MALLOC(sizeof(PiggyBank));

   if (pNew != NULL)

      MEMSET(pNew, 0x00, sizeof(PiggyBank));

   PiggyBank_AddRefs(pNew);

   return pNew;

}

 

static void PiggyBank_Free(PiggyBank **ppPiggyBank)

{

   … …

}

 

int PiggyBank_AddRefs(PiggyBank *pPiggyBank)

{

   … …

}

 

int PiggyBank_Release(PiggyBank *pPiggyBank)

{

   … …

}

 

void PiggyBank_Input(PiggyBank *pPiggyBank, int type)

{

   … …

}

void PiggyBank_Output(PiggyBank *pPiggyBank, int type)

{

   … …

}

 

int PiggyBank_GetTotal(PiggyBank *pPiggyBank, int type)

{

  … …

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值