I'm doing some kind of wrapper that looks like this:
#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());
}
And I'm getting this error:
Apply: no matching overloaded function found.void Apply(void (__thiscall T::* )(Value),T *,Value): template parameterValueis ambiguous, could beintorconst int &.void Apply(void (__thiscall T::* )(Value),T *,Value): could not deduce template argument forValuefromconst int.
So I get it that it comes from template parameter deduction, however I fail to understand how. Why would Value not evaluate to const int& both times?