I have a class which upon construction has a part which should be executed when the constructor has finished "enough" to make the call valid.
Take the following simplified class example (the actual problem is much more elaborate):
Explicitely creating a derived class allows me to properly implement the lambda to call a member of the class.
I can't seem to figure out how to do this for an explicit instantiation of the base class.
Can this be done ? Or is this a shortcoming of VS2012 or something the standard doesn't handle ?
Take the following simplified class example (the actual problem is much more elaborate):
Code:
#include <functional>
class base
{
public:
base(int i, std::function<void()> func) : mi(i)
{
func();
}
protected:
void foo() { }
int mi;
};
class derived : public base
{
derived(int i) :
base(i, [&](){ foo(); }) // can capture with [&] or [this]
{
}
};
int main()
{
// base b(14, [](){ foo(); }); // ??? doesn't compile
return 0;
}
I can't seem to figure out how to do this for an explicit instantiation of the base class.
Can this be done ? Or is this a shortcoming of VS2012 or something the standard doesn't handle ?