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