I’m trying to convert a construct like this:


template <class R, class T>

struct Foo {

            Foo(R (T::*m)) : member(m) {}

            R T::*member;



template <class R, class T>

Foo<R, T> makeFoo(R (T::*m)) {

            return Foo<R, T>(m);




struct S { int a; };



into something where the member pointer is a template parameter:


            template <class R, class T, R (T::*member)>

            struct Foo {};


            template <class R, class T, R (T::*member)>

            Foo<R, T, member> make Foo() {

                        return Foo<R, T, member>();



struct S { int a;};

makeFoo<int, S, &S::a>();


but this forces me to explicitly specify the return type and class type. This is exactly why I used the helper function in the first example. I’m sure there has to be a workaround somehow that’ll allow me to say something like the following and have the compiler deduce the missing parts:




I can’t think of a better place to ask than here.




Mats Nilsson