我尝试编译一个在我的linux机箱上使用boost regex库的boost程序。它具有所有必需的头文件和库。该程序拒绝编译抛出大量的模板输出。 我使用以下命令编译该程序。
请告知如何解决以下问题。
g ++ regex.cc -I / usr / local / include / boost / -L / usr / local / lib -lboost_regex -o regex
这是编译器的输出。
ravit@ravit-laptop:~$ g++ regex.cc -I/usr/local/include/boost/ -L/usr/local/lib -lboost_regex -o regex
In file included from /usr/local/include/boost/regex/v4/perl_matcher.hpp:582,
from /usr/local/include/boost/regex/v4/regex.hpp:88,
from /usr/local/include/boost/regex.hpp:31,
from regex.cc:19:
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp: In member function ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_assert_backref() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’:
/usr/local/include/boost/regex/v4/perl_matcher_non_recursive.hpp:180: instantiated from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_all_states() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:323: instantiated from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_prefix() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:207: instantiated from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match_imp() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:180: instantiated from ‘bool boost::re_detail::perl_matcher<BidiIterator, Allocator, traits>::match() [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/regex_match.hpp:50: instantiated from ‘bool boost::regex_match(BidiIterator, BidiIterator, boost::match_results<Iterator, Allocator>&, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type) [with BidiIterator = __gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, charT = char, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
/usr/local/include/boost/regex/v4/regex_match.hpp:82: instantiated from ‘bool boost::regex_match(const std::basic_string<charT, ST, SA>&, boost::match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>&, const boost::basic_regex<charT, traits>&, boost::regex_constants::match_flag_type) [with ST = std::char_traits<char>, SA = std::allocator<char>, Allocator = std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, charT = char, traits = boost::regex_traits<char, boost::cpp_regex_traits<char> >]’
regex.cc:30: instantiated from here
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:768: error: request for member ‘back’ in ‘((boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >*)this)->boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info<boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > [50]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:768: error: request for member ‘empty’ in ‘((boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >*)this)->boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info<boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > [50]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:778: error: request for member ‘back’ in ‘((boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >*)this)->boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info<boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > [50]’
/usr/local/include/boost/regex/v4/perl_matcher_common.hpp:778: error: request for member ‘empty’ in ‘((boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >*)this)->boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::recursion_stack’, which is of non-class type ‘boost::re_detail::recursion_info<boost::match_results<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > > > [50]’
这是从相同的boost正则表达式文档中获取的代码片段
#include <boost/regex.hpp>
#include <iostream>
void
print_captures(const std::string& regx,
const std::string& text)
{
boost::regex e(regx);
boost::smatch what;
std::cout << "Expression: \"" << regx << "\"\n";
std::cout << "Text: \"" << text << "\"\n";
if(boost::regex_match(text, what, e, boost::match_extra))
{
unsigned i, j;
std::cout << "** Match found **\n Sub-Expressions:\n";
for(i = 0; i < what.size(); ++i)
std::cout << " $" << i << " = \"" << what[i] << "\"\n";
std::cout << " Captures:\n";
for(i = 0; i < what.size(); ++i)
{
std::cout << " $" << i << " = {";
for(j = 0; j < what.captures(i).size(); ++j)
{
if(j)
std::cout << ", ";
else
std::cout << " ";
std::cout << "\"" << what.captures(i)[j] << "\"";
}
std::cout << " }\n";
}
}
else
std::cout << "** No Match found **\n";
}
int main(int , char* [])
{
print_captures("(([[:lower:]]+)|([[:upper:]]+))+", "aBBcccDDDDDeeeeeeee");
print_captures("a(b+|((c)*))+d", "abd");
print_captures("(.*)bar|(.*)bah", "abcbar");
print_captures("(.*)bar|(.*)bah", "abcbah");
print_captures("^(?:(\\w+)|(?>\\W+))*$", "now is the time for all good men to come to the aid of the party");
print_captures("^(?>(\\w+)\\W*)*$", "now is the time for all good men to come to the aid of the party");
print_captures("^(\\w+)\\W+(?>(\\w+)\\W+)*(\\w+)$", "now is the time for all good men to come to the aid of the party");
print_captures("^(\\w+)\\W+(?>(\\w+)\\W+(?:(\\w+)\\W+){0,2})*(\\w+)$", "now is the time for all good men to come to the aid of the party");
return 0;
}
答案 0 :(得分:2)
转到regex.cc文件,第30行(regex.cc:30:从此处实例化)和STARE(使用可行的文档中的示例进行交叉检查),直到明白你做错了什么为止。看来你在不支持这些操作的东西上调用back()和empty()。在这些错误消息[也称为非类型]的末尾给出[50],您可能忘记索引数组。 (即你已经编写了array.empty()而不是array [i] .empty())。
答案 1 :(得分:0)
错误:'......'中成员'.....'的请求通常是由使用。引起的。如果您不应该在声明处添加strong> - &gt; 或添加(),例如:
TheClass myTheClass();
而不是
TheClass myTheClass;