LoginSignup
7
4

More than 5 years have passed since last update.

オーバロードした関数をbindする

Posted at

次の様なクラス(構造体)が有るとして

struct A {
    void echo() {}
    void echo(int) {}
};

次のようなコードを書く。

A a;
std::bind(&A::echo, &a);
std::bind(&A::echo, &a, 10);

すると

No matching function for call to 'bind'

と怒られる。

対応方法

次のように書けば大丈夫

std::bind<void (A::*)()>(&A::echo, &a);
std::bind<void (A::*)(int)>(&A::echo, &a, 10);

または

std::bind(static_cast<void (A::*)()>(&A::echo), &a);
std::bind(static_cast<void (A::*)(int)>(&A::echo), &a, 10);
7
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
4