I am facing error C2783 with Visual C ++ (I can’t deduce the template argument), I have the following test case:
enum SPKType { A, B, C, D };
template<SPKType TypeCode, class ObjectType, typename U>
struct SPKSetterPattern
{
typedef void (ObjectType::* func)(U);
};
template<class ObjectType, typename U>
struct SPKSetterPattern<B,ObjectType,U> { typedef void (ObjectType::* func)(U,U); };
template<class ObjectType, typename U>
struct SPKSetterPattern<C,ObjectType,U> { typedef void (ObjectType::* func)(U,U,U); };
template<class ObjectType, typename U>
struct SPKSetterPattern<D,ObjectType,U> { typedef void (ObjectType::* func)(U,U,U,U); };
template<typename ObjectType, SPKType TypeCode>
struct helper
{
template<typename U>
static inline void add(ObjectType* obj, typename SPKSetterPattern<TypeCode,ObjectType,U>::func attrSetter) {}
};
class test
{
public:
template<typename ObjType>
void init()
{
helper<ObjType,A>::add(this, &test::setA);
helper<ObjType,A>::add(this, &test::setAf);
}
test() { init<test>(); }
void setA(int a) {}
void setB(float,float) {}
void setC(int,int,int) {}
void setD(int,int,int,int) {}
void setAf(double a) {}
void setBf(int,double) {}
};
int main()
{
test t;
return 0;
}
When commenting a line
static inline void add(ObjectType* obj, typename SPKSetterPattern<TypeCode,ObjectType,U>::func attrSetter) {}
and uncommenting the next line, the code compiles.
I don’t understand why, because for me the second argument "helper :: add" remains the same ...
Thanks for the help.