呃,好像我不能编辑或评论,所以我不得不发布这个作为答案。
我通过将规则拆分为 if 语句规则和 if-else 语句规则来解决这个问题。但是,问题又回到了我对 init 声明的定义。
init_decl
%= identifier
>> -('=' >> expression)
;
identifier
%= lexeme[(alpha | char_(''))
>> *(alnum | char('_'))]
;
expression
%= literal
;
literal
%= real_literal
| string_literal
;
real_literal
%= double_
;
string_literal
%= lexeme['"'
>> *(char_ - '"')
>> '"']
;
和以前一样的问题。但是,我第一次根本没有做好调查这个问题的工作。
In member function 'void boost::variant::convert_construct(T&, int, mpl_::false_) [with T = const Lang::Elements::Expression, T0_ = double, T1 = std::basic_string, std::allocator >, T2 = boost::detail::variant::void_, T3 = boost::detail::variant::void_, T4 = boost::detail::variant::void_, T5 = boost::detail::variant::void_, T6 = boost::detail::variant::void_, T7 = boost::detail::vari
就是这个方法:
template <typename T>
void convert_construct(
T& operand
, int
, mpl::false_ = mpl::false_() // is_foreign_variant
)
{
// NOTE TO USER :
// Compile error here indicates that the given type is not
// unambiguously convertible to one of the variant's types
// (or that no conversion exists).
//
indicate_which(
initializer::initialize(
storage_.address()
, operand
)
);
}</code>
Remember this error originates from the %= in the init_decl expression. The only variant in this expression is the one contained by the Expression object which is the expression rule's attribute value. The error seems to say that a variant (the type of object Expression contains) is trying to instantiate itself from an Expression, but I can't see this anywhere in the code. Anyway, I added cast operators to the Expression struct that exposes its underlying variant, but still I got the error.
The method that calls the method above is this:
template <typename T>
variant(const T& operand)
{
convert_construct(operand, 1L);
}</code>
It seems like it's trying to call this method instead:
template <typename Variant>
void convert_construct(
Variant& operand
, long
, mpl::true_// is_foreign_variant
)
{
convert_copy_into visitor(storage_.address());
indicate_which(
operand.internal_apply_visitor(visitor)
);
}</code>
这是导致此错误的编译器误解吗?