char* buff;
int lenth = INTVAL;
NewFunc( ?, INTVAL ); // 这里应该怎么写?
// NewFunc()应该如何声明?
先说NewFunc( )函数的声明和定义,声明如下:
int NewFunc( char** Buff, int BuffSize );
定义如下: int NewFunc( char** Buff, int BuffSize ){ char* tempBuff = NULL; // 如果直接 *Buff = new char[BuffSize];, // 如果申请失败还须将*Buff设为NULL try{ tempBuff = new char[BuffSize]; } catch(...){ return -1; } *Buff = tempBuff; // 内存申请成功后再将内存交给外部 return 0;}
int NewFunc( char** Buff, int BuffSize )
{
char* tempBuff = NULL; // 如果直接 *Buff = new char[BuffSize];,
// 如果申请失败还须将*Buff设为NULL
try{
tempBuff = new char[BuffSize];
}
catch(...){
return -1;
*Buff = tempBuff; // 内存申请成功后再将内存交给外部
return 0;
参数Buff是二级指针
调用NewFunc( )的方法如下:
NewFunc( *buff, INTVAL);
Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved. 闵涛 E_mail:admin@mintao.net(欢迎提供学习资源)
鄂公网安备 42011102001154号
站长:MinTao ICP备案号:鄂ICP备11006601号-18