Make your function support multi args (paras).

来源:互联网 发布:js数组元素赋值 编辑:程序博客网 时间:2024/05/17 21:50

void Reporter::record(unsigned int outType, RPT_MSGTYPE messageType, const char* format, ...)
{
    va_list args;

    // retrieve the variable arguments
    va_start( args, format );
    int     len;

#ifdef _MSC_VER
    int tem = _vscprintf( format, args );
    len = _vscprintf( format, args ) // _vscprintf doesn't count
        + 1; // terminating '/0'
#else
    char tmp[16];
    len = vsnprintf(tmp, sizeof(tmp)-1, format, args) + 4;
#endif
    char    buffer[1024] = "";
    vsprintf( buffer, format, args ); // C4996

    va_end(args);

    //must to construct a string type with the char* at here,
    //else it will call the record(,,const char* format, ...)
    //and will cause an calling circle
    record(outType, messageType, string(buffer));   

    //free(buffer);
}

原创粉丝点击