How do I fix the code below to store a lambda so I can invoke it at a later time?
The error I currently get is field ‘m_callback’ has incomplete type.
class Foo
{
public:
Foo() { }
~Foo() { }
template< typename FuncT >
void setCallback( FuncT&& callback )
{
m_callback = callback;
}
private:
auto m_callback; // this line is broken
};
int main(int argc, char** argv)
{
Foo foo;
foo.setCallback( [] (int x){ return true; } );
return 0;
}
The
autokeyword can’t be used liked that. I recommend using something like this:This is done from Visual Studio 2010.