为什么va_start会失败?

kam*_*mpi 2 c++ windows macros

我想创建一些日志记录,然后我创建了一个类.但是我将参数传递给它有一些问题.

类:

namespace debug
{
    class log
    {
        private:    // Members
            const std::string context;
            int Type;
        public:     // Methods
            void message( int Type, const std::string& message, ... );

        public:     // Constructor, Destructor
            log( const std::string& context, int Type );
            ~log();
    };//class log
}//namespace debug     

namespace debug
{
    void log::message( int Type, const std::string& message, ... )
    {
        va_list args;
        int len;

        char    *buffer;

        va_start( args, message );

        len = _vscprintf( message.c_str(), args ) + 1; // _vscprintf doesn't count terminating '\0'
        buffer = ( char* )malloc( len * sizeof( char ) );

        vsprintf_s( buffer, len, message.c_str(), args );

        va_end( args );

    }//log::message
}//namespace debug
Run Code Online (Sandbox Code Playgroud)

我定义了两个宏:

#define DEBUG_METHOD( Type )  debug::log _debugLog( __FUNCTION__, Type );
#define DEBUG_MESSAGE( Type, debug_message, ... ) { _debugLog.message( Type, debug_message, ##__VA_ARGS__ ); }
Run Code Online (Sandbox Code Playgroud)

我在这样的函数中使用它们:

BOOL test( BOOL *bTestVal)
{
   DEBUG_METHOD( INFO );
   DEBUG_MESSAGE( INFO, "Argument1 = '%s'", BoolToString( ( BOOL )*bTestVal) );

       //here comes some work...
}
Run Code Online (Sandbox Code Playgroud)

不幸的是我总是收到错误.这一行len = _vscprintf( message.c_str(), args ) + 1;总是会抛出错误.我认为va_start是造成这种情况,因为args它具有价值+ args 0x0052eed8 "ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ... char *

有人可以帮助我,我做错了吗?

提前致谢!

Igo*_*nik 6

18.10/3 ...该参数parmN是函数定义的变量参数列表中最右边的参数的标识符(恰好在...之前).如果parmN使用函数,数组或引用类型声明参数,或者使用与传递没有参数的参数时生成的类型不兼容的类型,则行为未定义.

强调我的.