Код: Выделить всё
template
class ActionItem{
public:
ActionItem(Action_F action_)
: action(action_)
{}
Action_F action;
};
< /code>
Как я могу создать переменную члена этого класса? < /p>
class A{
int v;
// does not work - template arg is not deduced automatically
//ActionItem a{[this](){ doSomething(v);}};
// does not work - auto not allowed for non-static member
// auto a = ActionItem{[this](){ doSomething(v);}};
// this works but is less elegant:
struct DoSmth{
int& v;
void operator()(){
doSomething();
}
};
ActionItem a{DoSmth{v}};
};
Подробнее здесь: https://stackoverflow.com/questions/796 ... this-class