无法使用 std::function 进行编译以传递 void 函数作为参数

发布于 2025-01-14 21:31:48 字数 1366 浏览 2 评论 0原文

我遵循了我在互联网上看到的想法:

UpdateColumnIndexVector(m_vColumnIndexesToExclude, WriteColumnIndexesToExclude);

调用:

void CCreateReportDlg::UpdateColumnIndexVector(ColumnIndexVector &rvData, std::function<void()> WriteToRegistry)
{
    bool bModified = true;
    // Code simplified

    if (bModified)
    {
        WriteToRegistry();
    }
}

传入的函数:

void CCreateReportDlg::WriteColumnIndexesToExclude()
{
    ByteVector vData(m_vColumnIndexesToExclude.begin(), m_vColumnIndexesToExclude.end()); // int to BYTE

    const CString strSection = theApp.GetActiveScheduleSection(_T("Options"));

    theApp.WriteProfileVector(strSection, _T("AssignStatesEx"), vData);
}

当我编译时:

错误C3867:CCreateReportDlg::WriteColumnIndexesToExclude:非标准语法;使用 & 创建指向成员的指针

但是,如果我将此行更改为:

UpdateColumnIndexVector(m_vColumnIndexesToExclude, &WriteColumnIndexesToExclude);

这也不能编译:

错误C2276:&:对绑定成员函数表达式进行非法操作

错误 C2660:CCreateReportDlg::UpdateColumnIndexVector:函数不接受 1 个参数

WriteColumnIndexesToExclude 是对话框类的 private 成员。

我做错了什么?

附言。我的项目是MFC C++ 对话框。

I have followed the ideas I saw on the internet:

UpdateColumnIndexVector(m_vColumnIndexesToExclude, WriteColumnIndexesToExclude);

That calls:

void CCreateReportDlg::UpdateColumnIndexVector(ColumnIndexVector &rvData, std::function<void()> WriteToRegistry)
{
    bool bModified = true;
    // Code simplified

    if (bModified)
    {
        WriteToRegistry();
    }
}

The function being passed in:

void CCreateReportDlg::WriteColumnIndexesToExclude()
{
    ByteVector vData(m_vColumnIndexesToExclude.begin(), m_vColumnIndexesToExclude.end()); // int to BYTE

    const CString strSection = theApp.GetActiveScheduleSection(_T("Options"));

    theApp.WriteProfileVector(strSection, _T("AssignStatesEx"), vData);
}

When I compile:

error C3867: CCreateReportDlg::WriteColumnIndexesToExclude: non-standard syntax; use & to create a pointer to member

Yet, if I change this line to:

UpdateColumnIndexVector(m_vColumnIndexesToExclude, &WriteColumnIndexesToExclude);

That does not compile either:

error C2276: &: illegal operation on bound member function expression

error C2660: CCreateReportDlg::UpdateColumnIndexVector: function does not take 1 arguments

WriteColumnIndexesToExclude is a private member of the dialog class.

What am I doing wrong?

PS. My project is MFC C++ Dialog.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文