问题描述
|
我试图编译一个在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::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,traits>::match_all_states() [with BidiIterator = __gnu_cxx::__normal_iterator<const 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,traits>::match_prefix() [with BidiIterator = __gnu_cxx::__normal_iterator<const 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,traits>::match_imp() [with BidiIterator = __gnu_cxx::__normal_iterator<const 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,traits>::match() [with BidiIterator = __gnu_cxx::__normal_iterator<const 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*,charT = 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,SA>::const_iterator,boost::regex_constants::match_flag_type) [with ST = std::char_traits<char>,SA = std::allocator<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::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<const char*,boost::regex_traits<char,boost::cpp_regex_traits<char> > >*)this)->boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<const 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::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::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::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::allocator<char> > > > > > > [50]’
这是同一boost regex文档中的代码片段
#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;
}
解决方法
转到regex.cc文件的第30行(regex.cc:30:从此处实例化)并对其进行存储(与确实有用的文档中的示例进行交叉检查),直到清楚您做错了什么。似乎您正在对不支持这些操作的东西调用back()和empty()。在这些错误消息的末尾给出[50] [也表示非类类型]时,您可能忘记了为数组建立索引。 (即您编写了array.empty()而不是array [i] .empty())。
,错误:\'......'中成员'.....'的请求通常是由于使用之一引起的。在不应该使用->或在声明时添加()的情况,例如:
TheClass myTheClass();
代替
TheClass myTheClass;