The following code does not compile. Why is this restriction, and how can I bypass it? If I replace the variant declaration, it compiles.
struct PPP
{
int xxx;
PPP() : x(xxx) {} // error: No matching constructor for initialization of 'std::variant<Inner1, Inner2>'
struct Inner1
{
Inner1(int &x ) : c(x) {}
int &c;
};
struct Inner2
{
Inner2(int &x ) : c(x) {}
int &c;
};
struct Inner3 {};
std::variant<Inner1, Inner2> x;
// std::variant<Inner1, Inner3> x; // This will cause the code to compile
};