Suppose you have the following code
template<typename T,void (T::*m)(int)>
struct B{
void f(T* a,int x){
(a->*m)(x);
}
};
struct A{
template<typename X> void f(int){
}
void wrap(int i){
f<char>(i);
}
B<A,&A::f<char> > y;
};
int main(){
A a;
}
This definition
B<A,&A::f<char> > y;
works with gcc,but not with Visual studio 2010:
error C2440: 'specialization' : cannot convert from 'overloaded-function' to 'void (__thiscall A::* )(int)'
On the contrary,
B<A,&f<char> > y;
works with visual studio but not with gcc.
Note that B<A,&A::f<char> > y; placed in the main, i.e.
int main(){
B<A,&A::f<char> > y;
}
works for VS as well.
IS B<A,&f<char> > y; not standard? is there a way (apart wrapping the template function) to make the thing compile with both compilers?
===EDIT====
A possible, dirty solution is
#ifdef _WIN32
#define vsFix(a,b) b
#else
#define vsFix(a,b) a::b
#endif
B<A,&vsFix(A,f)<char> > y;
No.
&f<char>is a pointer to function, not pointer to member function.Yes, by fixing the types, and passing pointer to object of type A :