FastDelegate
refers to http://www.codeproject.com/KB/cpp/FastDelegate.aspx, but I don't think it is related.
I have code like following, and got error.
#include <FastDelegate.h>
using namespace fastdelegate;
template <typename T>
T Getter() {}
template <typename T>
void Setter(T) {}
template <typename T>
class Prop
{
public:
typedef FastDelegate0<T> Getter;
typedef FastDelegate1<T> Setter;
Prop(Getter getter, Setter setter) :
m_Getter(getter), m_Setter(setter)
{
}
private:
Getter m_Getter;
Setter m_Setter;
};
template <typename T>
inline Prop<T>* MakeProp(FastDelegate0<T> getter, FastDelegate1<T> setter)
{
return new Prop<T>(getter, setter);
}
static int Target = 0;
int main()
{
FastDelegate0<int> fdGetter(Getter<int>);
Prop<int>* c = MakeProp(fdGetter, Setter<int>);
// ^^^^ error: no matching function for call to 'MakeProp'
}
If changed the main()
to:
int main()
{
FastDelegate0<int> fdGetter(Getter<int>);
FastDelegate1<int> fdSetter(Setter<int>);
Prop<int>* c = MakeProp(fdGetter, fdSetter); // It works.
}
or:
int main()
{
FastDelegate0<int> fdGetter(Getter<int>);
Prop<int>* c = MakeProp<int>(fdGetter, Setter<int>); // It works, too.
}
I think, MakeProp()
should get the T
from fdGetter (which is int
, than called the contructor of FastDelegate1<int>
automatically. But it did not. Why?
P.S. I would like to save the getter and setter in Prop
, any suggestion for this approach is welcome. Maybe it is bad to copy the instance of FastDelegate* during passing arguments in function.
Have you tried
Prop<int>* c = MakeProp(FastDelegate0<int>(Getter<int>), FastDelegate1<int>(Setter<int>));
?
Setter<int>
cannot be converted to FastDelegate1<T>
!