【问题标题】:Too few arguments for call调用的参数太少
【发布时间】:2017-10-25 23:38:01
【问题描述】:

所以基本上在其他编译器(Visual Studio 2003-2012)中这是可以的,但在 Visual Studio 2013 中则不是。有什么问题?错误就在我的注释行。

“theParameters”声明为:

#define theClass    CDPClient
#define theParameters   CAr & ar, DPID dpidUser, LPVOID lpBuffer, u_long uBufSize

void CDPClient::UserMessageHandler( LPDPMSG_GENERIC lpMsg, DWORD dwMsgSize, DPID idFrom )
{
    m_pDump = (BYTE*)lpMsg;
    m_nDumpSize = dwMsgSize;

    BYTE* pData = (BYTE*)lpMsg;
    for (DWORD i=0;i<dwMsgSize;i++)
    {
        pData[i] = pData[i] ^ ((BYTE)(i & 0xff) ^ 169);
        pData[i] = pData[i] ^ ((0xff - (BYTE)(i & 0xff)) ^ 86);
    }

    CAr ar((LPBYTE)lpMsg, dwMsgSize);
    GETTYPE( ar );

    void ( theClass::*pfn )( theParameters )    =   GetHandler( dw );

    if (pfn) {
        (this->*(pfn))(ar); // (ar) -> too few arguments for call. Why?
    }
    else{
        //g_DPCacheSrvr.Send( lpBuf, uBufSize, dpidUser );
    }

    m_pDump = NULL;
    m_nDumpSize = 0;
}

【问题讨论】:

  • 什么是theParameters
  • 嗨,我已经添加了“theParameters”是什么。
  • theParameters 是一个扩展为 4 个参数的宏。您只使用一个参数调用该函数。您缺少 dpidUserlpBufferuBufSize 参数。
  • 请删除宏,使用 nullptr、const 和 size_t。
  • 您好,我这样做了“(this->*(pfn))(ar, dpidUser, lpBuffer, uBufSize);"但它认为它没有定义。

标签: c++ visual-c++ visual-studio-2012


【解决方案1】:

您有一个宏 theParameters,它被 4 个参数替换。因此调用需要 4 个参数,但您只提供一个 ar

您可以阅读有关宏的更多信息 here。标识符只是被定义的任何内容替换。所以在你的代码中,

void ( theClass::*pfn )( theParameters ) = GetHandler( dw );

变成

void ( theClass::*pfn )( CAr &amp; ar, DPID dpidUser, LPVOID lpBuffer, u_long uBufSize ) = GetHandler( dw );

【讨论】:

  • 您好,是的,这是正确的,我这样做了“(this->*(pfn))(ar, dpidUser, lpBuffer, uBufSize);"而不是“(this->*(pfn))(ar);”但我仍然有错误:O
  • 同样的错误,还是别的什么?您编写的参数没有定义,您首先需要定义它们。我认为这可能是一个错误。
  • 非常感谢您指出这一点。我的头好痛,我不知道该怎么办等等。谢谢!
猜你喜欢
  • 2017-04-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-08
  • 2019-07-27
  • 2011-11-15
  • 2021-05-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多