std::bind の失敗で出る call to non-static member function without an object argument ― 2021年03月31日 12時17分44秒
% c++ bind.cpp
bind.cpp:11:28: error: call to non-static member function without an object
argument
auto f = std::bind( C::func, c );
~~~^~~~
1 error generated.
これに対応するコードはこちら。
#include <functional>
struct C
{
void func(){};
};
int main()
{
C c;
auto f = std::bind( C::func, c );
}
% c++ bind.cpp
これを修正するとこうなる。
auto f = std::bind( &C::func, c );
「&」が抜けているのが間違い。C::func で関数名を指定しているが、そのアドレスを渡すのを忘れているのが原因。
コメント
トラックバック
このエントリのトラックバックURL: http://uyota.asablo.jp/blog/2021/03/31/9362336/tb
※なお、送られたトラックバックはブログの管理者が確認するまで公開されません。
コメントをどうぞ
※メールアドレスとURLの入力は必須ではありません。 入力されたメールアドレスは記事に反映されず、ブログの管理者のみが参照できます。
※なお、送られたコメントはブログの管理者が確認するまで公開されません。