Question: Consider the following code

```
template<typename T, int N>
struct A {
  typedef T value_type; // OK. save T to value_type
  static const int size = N; // OK. save N to size
};

```

Look, it is possible to save any template parameter if this parameter is a typename or an integer value. The thing is that *pointer to member* is an offset, i.e. integer.
Now I want to save any pointer to member in compile time:

```
struct Foo {
   int m; 
   int r;
};

template<int Foo::*ptr_to_member>
struct B {
   // Next statement DOES NOT WORK!
   static int Foo::* const saved_ptr_to_member = ptr_to_member; 
};

// Example of using
int main() {
    typedef B<&Foo::m> Bm;
    typedef B<&Foo::r> Br;
    Foo foo;
    std::cout << (foo.*(Bm::saved_ptr_to_member));
}

```

How to save pointer to member in **compile time**? I use VS2008.

**Note.** Compile time is critical. Please don't write run-time solution. I know it.

Answer: 
You can't.

But you can use a [functionoid](http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.10) instead. This *can* be a compile-time solution. And because the compiler can inline things, it's possibly even faster than a pointer to a member function. Example:

```
struct Foo {
   int m; 
   int r;
};

struct FooM {
   static int call(Foo const &foo) const { return foo.m; }
}

struct FooR {
   static int call(Foo const &foo) const { return foo.r; }
}

template<typename FooFun>
struct B {
   typedef FooFun foo_fun;
   int call_foo_fun(Foo const &foo) { return foo_fun::call(foo); }
};

// Example of using
int main() {
    typedef B<FooM> Bm;
    typedef B<FooR> Br;
    Foo foo;
    std::cout << Bm.call_foo_fun(foo);
}

```

Untested, but you get the idea.
You can't initialize a static member inside the definition of a struct. It needs to be declared outside like this (which is probably not what you intended with the template, but anyway):

```
struct Foo {
   int m; 
   int r;
};

template<int Foo::*ptr_to_member>
struct B {
   static int Foo::* const saved_ptr_to_member; 
};

int Foo::* const B<&Foo::m>::saved_ptr_to_member = &Foo::m; 
int Foo::* const B<&Foo::r>::saved_ptr_to_member = &Foo::r; 

// Example of using
int main() {
    typedef B<&Foo::m> Bm;
    typedef B<&Foo::r> Br;
    Foo foo;
    std::cout << (foo.*(Bm::saved_ptr_to_member));
}

```