Access std::variant inside lambda
问题 I have the following code: std::variant<std::uint32_t, std::uint16_t, float> my_variant; template <typename T> void my_sub_func(T& value) { // do stuff }; void my_func(my_variant& value) { [&]() { my_sub_func(std::get<std::uint32_t>(value)); }; }; int main() { my_variant t; my_func(t); } I always get an Unexpected index exception at runtime, why is that and how can I avoid it? 来源: https://stackoverflow.com/questions/61930744/access-stdvariant-inside-lambda