How to wrap a function with variable length arguments?

后端 未结 7 2058
借酒劲吻你
借酒劲吻你 2020-12-05 12:54

I am looking to do this in C/C++.

I came across Variable Length Arguments but this suggests a solution with Python & C using libffi.

Now, if I want to wr

7条回答
  •  星月不相逢
    2020-12-05 13:17

    I am also unsure what you mean by pure

    In C++ we use

    #include 
    #include 
    
    class Foo
    {   void Write(const char* pMsg, ...);
    };
    
    void Foo::Write( const char* pMsg, ...)
    {
        char buffer[4096];
        std::va_list arg;
        va_start(arg, pMsg);
        std::vsnprintf(buffer, 4096, pMsg, arg);
        va_end(arg);
        ...
    }
    

提交回复
热议问题