&decltype(obj)::member not working

c++, c++11, decltype, pointer-to-member

Solution

`decltype` as a nested-name-specifier was added into C++11 at a relatively late stage; n3049 as the resolution to DR 743 (and DR 950). n3049 was published in March 2010, which is probably why it hasn't found its way into VC++ yet.

The workaround is to use the identity typefunction:

template<typename T> using id = T;
id<decltype(expression)>::member;

Problem

Why is does this not work (Visual C++ 2012 Update 1), and what is the proper way to fix it? ``` #include <boost/lambda/bind.hpp> namespace bll = boost::lambda; struct Adder { int m; Adder(int m = 0) : m(m) { } int foo(int n) const { return m + n; } }; #define bindm(obj, f, ...) bind(&decltype(obj)::f, obj, __VA_ARGS__) int main() { return bll::bindm(Adder(5), foo, bll::_1)(5); } ```

Original source