I reproduced the problem with VS2010. You should call the example function, though:
#include <functional> struct SomeT { static int magic(unsigned char*) { return 42; } }; template<typename T> void example() { std::function<int (unsigned char*)> test = [=](unsigned char* start) -> int { return T::magic(start); }; } int main() { example<SomeT>(); }
Update based on OP comment:
It works:
#include "stdafx.h" #include <functional> struct SomeT { static int magic(unsigned char*) { return 42; } }; template<typename T> void example() { auto func = T::magic; std::function<int (unsigned char*)> test = [=](unsigned char* start) -> int { return func(start); }; } int main() { example<SomeT>(); }
I was looking for workarounds, but so far nothing is working, I tried this nice permutation, including this nice permutation, but so far have failed:
template<typename T> void example() { static const T* workaround; std::function<int (unsigned char*)> test = [=](unsigned char* start) -> int { typedef decltype(*workaround) innerT; return innerT::magic(start); }; }
Hard ... Strike>
source share