我在玩gb reasearch的axe解析器框架,但在使用gcc 4.6.2时遇到了问题。使用VC++10-Compiler没有任何问题。
这行代码:
auto space = axe::r_any(" \t");
// trailing spaces
auto trailing_spaces = *space & (comma | endl);
错误:
D:\Projekte\axeparser-build-desktop-Qt_4_8_0__Qt480mingw__Debug\..\axeparser\main.cpp:19: error: conversion from 'axe::r_and_t<axe::r_many_t<axe::r_pred_t<axe::is_any_t<const char*> >&, axe::r_empty_t>, axe::r_or_t<axe::r_char_t<char>&, axe::r_char_t<char>&> >' to non-scalar type 'axe::r_and_t<axe::r_many_t<axe::r_pred_t<axe::is_any_t<const char*> >&, axe::r_empty_t>&, axe::r_or_t<axe::r_char_t<char>&, axe::r_char_t<char>&>&>' requested
我正在使用PDF中的CSV示例。下面是我使用的代码:
#include <iostream>
#include <axe.h>
#include <iostream>
#include <string.h>
using namespace std;
template<class I>
void csv(I begin, I end)
{
// define comma rule
auto comma = axe::r_lit(',');
// endl matches end of line symbol
auto endl = axe::r_lit('\n');
// space matches ' ' or '\t'
auto space = axe::r_any(" \t");
// trailing spaces
auto trailing_spaces = *space & (comma | endl);
std::string value;
// create extractor to print matched value
auto print_value = axe::e_ref([&value](I, I)
{
std::cout << "<" << value << ">";
});
// rule for comma separated value
auto csv_str = *space & +(axe::r_printable() - trailing_spaces)
>> value & *space;
// rule for single string of comma separated values
auto line = *((csv_str & comma) >> print_value)
& csv_str >> print_value
& endl >> axe::e_ref([](I, I)
{
std::cout << "\n";
});
// file contaning many csv lines
auto csv_file = +line | axe::r_fail([](I i1, I i2) {
std::cout << "\nFailed: " << std::string(i1, i2);
});
csv_file(begin, end);
}
int main()
{
auto space = axe::r_lit(' ');
auto spaces = space & space & space;
std::string moin = "232323233";
csv(moin.begin(), moin.end());
}
有没有人能帮我纠正这个错误?gcc 4.6不能处理自动打字吗?我得到了与|(或-操作符)相同的错误。该怎么办呢?
非常感谢!
发布于 2012-05-19 04:57:48
这是gcc 4.6.x版本中的一个错误,已在4.7.0版本中修复。如果你不能升级编译器,那么就用axe::r_rule<Iterator>
代替auto
。
https://stackoverflow.com/questions/9467710
复制相似问题