0
私は次のコードを持っている:のstd ::はstdの引数としてバインド::バインド
static std::vector<std::multimap<float, std::function<void(void)> > > LoadedDelegates;
std::function<void(FVector2D, std::function<void(ASwatterFly*)>)> ShooterFunc = [this](FVector2D Input, std::function<void(ASwatterFly*)> InputFly)
{
this->RemainingFlies.Add(this->MakeShooterFly(Input, InputFly));
};
LoadedDelegates.push_back(std::multimap<float, std::function<void(void)> >
{
{
3.f,
std::bind(ShooterFunc, FVector2D(1.f, 0.f), std::bind(&ASwatterLevelBase::ShootAndScootMisdirection, this, std::placeholders::_1, FVector2D(0.f, 0.f), 8))
}
});
を私はstd::function<void(ASwatterFly*)> >
からstd::function<void(void)> >
に変換するために別のバインドの内部バインドを持っています。このコードスニペットはコンパイルされません。しかし、バインドを変数に移動して、次のように渡すと:
static std::vector<std::multimap<float, std::function<void(void)> > > LoadedDelegates;
std::function<void(FVector2D, std::function<void(ASwatterFly*)>)> ShooterFunc = [this](FVector2D Input, std::function<void(ASwatterFly*)> InputFly)
{
this->RemainingFlies.Add(this->MakeShooterFly(Input, InputFly));
};
std::function<void(ASwatterFly*)> TestFunc = std::bind(&ASwatterLevelBase::ShootAndScootMisdirection, this, std::placeholders::_1, FVector2D(0.f, 0.f), 8);
LoadedDelegates.push_back(std::multimap<float, std::function<void(void)> >
{
{
3.f,
std::bind(ShooterFunc, FVector2D(1.f, 0.f), TestFunc)
}
});
これが機能します。この場合、2番目のバインドを変数として渡してコンパイルする必要があるのはなぜですか?
私の問題はおそらくstd :: bindは、最初の例で使用したときの戻り値の型を推定できないことに気付きました。今度はstd :: bindを以下のようにキャストしようとしました: 'std :: function(std :: bind(&ASwatterLevelBase :: ShootAndScootMisdirection、this、std :: placeholders :: _ 1、FVector2D 'エラーC4868:ブレースされたイニシャライザリストでコンパイラが左から右の評価順序を強制しない ' 明示的にstdをキャストするにはどうすればよいですか? ::バインド? –
Rael
今私はそれについて考えていますが、最初のstd :: bindは正しく評価されているので、私は今も確信していません。 – Rael
申し訳ありませんが、[この質問](http://stackoverflow.com/questions/25841857/vc2013-function-from-bind-not-compiling/25842919#25842919)の回答が私の問題になるようです最初の例がうまくいかない理由を説明します。バインドの引数であるバインドの場合は、std :: functionでラップする必要があるからです。しかし、それはキャスティングに関する私の以前のコメントに戻る。私はどのようにstd ::のバインドをラップして、それはコンパイルされるだろうか? – Rael