c++ variant class member stored by reference
问题 I am trying to experiment with std::variant. I am storing an std::variant as a member of a class. In the below code, things work fine if the variant is stored by value, but does not work (for the vector case, and for custom objects too) if the variant is stored by reference. Why is that? #include <variant> #include <vector> #include <iostream> template<typename T> using VectorOrSimple = std::variant<T, std::vector<T>>; struct Print { void operator()(int v) { std::cout << "type = int, value =