Original Post
The following doesn't compile in VC++ 8: This works in GCC and Borland. Is it legal C++? Is there some trick to get this to work in VC++? The background and motivation for this construct comes from this recent thread.
struct Foo
{
int a, b;
int getB() const { return b; }
};
template <class T> struct Bar
{
template <class M, M T::* m> void add() { /* do something with member_ptr */ }
template <class M, M (T::* m)() const> void add() { /* do something with member_function_ptr */ }
};
int main(int argc, char** argv)
{
Bar<Foo> bar;
bar.add<int, &Foo::a>();
bar.add<int, &Foo::getB>();
return 1;
}