Stack overflow при использовании boost::recursive_wrapper
От: Аноним  
Дата: 05.04.10 11:50
Оценка:
Почему-то попытка использовать рекурсивный тип с помощью boost::variant/boost::recursive_wrapper приводит к переполнению стека (пример кода — ниже).


#include <boost/variant.hpp>
#include <iostream>

using boost::apply_visitor;
using boost::variant;
using std::cout;
using std::endl;

struct A {};
struct B {};
struct C {};
struct D;

typedef variant<A,B,C,boost::recursive_wrapper<D> > ABCD;

struct D {
    D() { v = A();}
    D(const A& a) : v(a) { }
    D(const B& b) : v(b) { }
    D(const C& c) : v(c) { }
    D(const D& d) : v(d) { }
    ABCD v;
};

class MyVisitor : public boost::static_visitor<>
{
public:
    void operator() (const A&) const
    {
        cout << "It's A!" << endl;
    }

    void operator() (const B&) const
    {
        cout << "It's B!" << endl;
    }

    void operator() (const C&) const
    {
        cout << "It's C!" << endl;
    }

    void operator() (const D& d) const
    {
        cout << "It's D->";
        boost::apply_visitor( MyVisitor(), d.v );
    }
};


int main()
{
    A a = A();
    D d = D(a);
    D d1 = D(d);
    ABCD v = d1;
    boost::apply_visitor( MyVisitor(), v );
    return 0;
}


Буду благодарен за любые идеи — что не так?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.