Вопрос

Do you have any idea how to solve or get around this problem?

http://boost.2283326.n4.nabble.com/Variant-recursive-wrapper-and-ambiguous-convert-construct-td4543139.html

#include <boost/variant.hpp>
class b_fwd;
typedef boost::variant<boost::recursive_wrapper<b_fwd> > a;
class c_fwd;
typedef boost::variant<boost::recursive_wrapper<c_fwd> > b;

struct b_fwd : b {
  // inherit constructors
  template <typename... Ts> b_fwd(Ts... o) : b(o...) {}
};

typedef boost::variant<double, char *> c;

struct c_fwd : c {
  // inherit constructors
  template <typename... Ts> c_fwd(Ts... o) : c(o...) {}
};

void f(const b &b_node) 
{
    a a_node(b_node); 
}

int main() 
{
}
Это было полезно?

Решение

I had a hunch in reaction to GuyGreer's comment.

If the problem is caused by variant being assignable/convertible to variant, then maybe we can disambiguate by using a third, isolated, variant:

a a_node(boost::variant<b>(b_node)); 

Lo and behold, homeopathy seems to work :)

See it Live On Coliru

I have no idea whether this "works" in the sense that the OP expects, because, frankly, the OP's code was a mystery to me

#include <boost/variant.hpp>
class b_fwd;
typedef boost::variant<boost::recursive_wrapper<b_fwd> > a;
class c_fwd;
typedef boost::variant<boost::recursive_wrapper<c_fwd> > b;

struct b_fwd : b {
    using b::b;
};

typedef boost::variant<double, char *> c;

struct c_fwd : c {
    using c::c;
};

void f(const b &b_node) 
{
    a a_node(boost::variant<b>(b_node)); 
}

int main() 
{
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top