私は次のようなラッパーをやっています:
#include <iostream>
template<class T, class Value>
void Apply(void (T::*cb)(Value), T* obj, Value v)
{
(obj->*cb)(v);
}
class Foo
{
public:
void MyFunc(const int& i)
{
std::cout << i << std::endl;
}
const int& GetValue()
{
return i_;
}
private:
int i_ = 14;
};
int main()
{
Foo f;
Apply(&Foo::MyFunc, &f, f.GetValue());
}
そして、私はこのエラーが発生しています:
Apply
: 一致するオーバーロードされた関数が見つかりません。void Apply(void (__thiscall T::* )(Value),T *,Value)
: テンプレート パラメータがあいまいです。またはValue
の可能性があります。int
const int &
void Apply(void (__thiscall T::* )(Value),T *,Value)
Value
: fromのテンプレート引数を推定できませんでしたconst int
。
したがって、それはテンプレート パラメーターの推定によるものだとわかりますが、その方法がわかりません。両方の時間に評価されValue
ないのはなぜですか?const int&