【发布时间】:2018-12-20 22:34:28
【问题描述】:
我有以下代码:
void MyClass::create_msg(MyTime timestamp) {
// do things here ...
}
我尝试为上述函数创建一个 std::bind:
MyMsg MyClass::getResult(MyTime timestamp) {
// do things here ...
std::bind(create_msg(), timestamp);
// do things ...
}
但出现以下错误:
error: too few arguments to function call, single argument 'timestamp' was not specified
std::bind(create_msg(), timestamp);
~~~~~~~~~~ ^
MyClass.cpp:381:1: note: 'create_msg' declared here
void MyClass::create_msg(MyTime timestamp) {
^
1 error generated.
在这种情况下我做错了什么?谢谢!
顺便说一句,如果我这样做,同样的错误:
std::bind(&MyClass::create_msg(), this, timestamp);
【问题讨论】:
-
是否有理由在 lambda 上使用
bind? -
@pstrjds 但它是一个成员函数,所以它必须是
std::bind(&MyClass::create_msg, this, timestamp) -
@clcto - 你是对的 - 我的错。我打字很快,忘了考虑它是一个成员函数。
-
在
&MyClass::create_msg()中去掉括号->&MyClass::create_msg