Boost logo

Boost Users :

Subject: Re: [Boost-users] Overcoming AST forward declaration (includes online example)
From: Gavin Lambert (boost_at_[hidden])
Date: 2018-11-05 05:01:23

On 3/11/2018 11:34, Michael Powell wrote:
> The forward declaration errors now the top most errors:

Fundamentally you have a cyclic recursion problem.

You're trying to declare that ast_msg_body_t contains by value a variant
which can contain a ast_group_t which can contain an ast_msg_body_t (and
similarly for the other possible variant types).

There is no possible way this could compile, as this requires the type
to be infinite size.

You will need to restructure things; in some cases you can rewrite
things to use lists, although that's probably not appropriate here. In
this case you probably need to introduce an indirection and kick
something onto the heap rather than the stack.

For example, you could make the body members into unique_ptrs. This
would also let you make the body type use inheritance-based polymorphism
rather than using a variant (which one is better depends on taste and on
intended usage).

(Also, while I'm not familiar with Spirit: there should be a way to make
it output actual int values rather than strings, unless you need to
preserve the input format.)

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at