无法使用 std::function 进行编译以传递 void 函数作为参数
我遵循了我在互联网上看到的想法:
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 expressionerror 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论