Easy
std::visit with a visitor that omits one alternative
A new alternative, double, is added to Shape. The visitor lambda overload set passed to std::visit is not updated to handle it. What happens?
main.cpp
#include <variant>
#include <iostream>
#include <string>
struct Circle { double r; };
struct Square { double s; };
using Shape = std::variant<Circle, Square, double>; // double added later
struct AreaVisitor {
double operator()(const Circle& c) const { return 3.14 * c.r * c.r; }
double operator()(const Square& s) const { return s.s * s.s; }
// no overload for double
};
int main() {
Shape shape = 2.5;
std::cout << std::visit(AreaVisitor{}, shape) << "\n";
}16 of 44 in Design Patterns