gpt4 book ai didi

c++ - 为什么预先声明 std::basic_string 会破坏 boost::regex?

转载 作者:太空宇宙 更新时间:2023-11-04 14:49:24 26 4
gpt4 key购买 nike

使用带有 boost 1.53 的 Microsoft Visual Studio 2012 编译器,我有一些工作代码使用了:

#include <boost/regex.hpp>

后来我在regex.hpp之前包含的头文件中添加了以下两行:

namespace std {template<class T> class basic_string<T>;}
typedef std::basic_string<TCHAR> tstring;

现在我得到一堆编译错误,但如果在这些其他行之前包含 regex.hpp,则没有错误。

许多错误中的前几个是:

c:\program files (x86)\boost\boost_1_53\boost\regex\v4\instances.hpp(106): error C2027: use of undefined type 'std::basic_string<_Elem,_Traits,_Alloc>'
19> with
19> [
19> _Elem=char16_t,
19> _Traits=std::char_traits<unsigned short>,
19> _Alloc=std::allocator<char16_t>
19> ]
19>c:\program files (x86)\boost\boost_1_53\boost\regex\v4\instances.hpp(106): error C2065: 'const_iterator' : undeclared identifier
19>c:\program files (x86)\boost\boost_1_53\boost\regex\v4\instances.hpp(106): error C2923: 'boost::match_results' : 'const_iterator' is not a valid template type argument for parameter 'BidiIterator'
19>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(364): error C2825: '_Iter': must be a class or namespace when followed by '::'
19> c:\program files (x86)\boost\boost_1_53\boost\regex\v4\iterator_traits.hpp(116) : see reference to class template instantiation 'std::iterator_traits<_Iter>' being compiled
19> with
19> [
19> _Iter=int
19> ]
19> c:\program files (x86)\boost\boost_1_53\boost\regex\v4\match_results.hpp(68) : see reference to class template instantiation 'boost::re_detail::regex_iterator_traits<T>' being compiled
19> with
19> [
19> T=int
19> ]
19> c:\program files (x86)\boost\boost_1_53\boost\regex\v4\instances.hpp(106) : see reference to class template instantiation 'boost::match_results<BidiIterator>' being compiled
19> with
19> [
19> BidiIterator=int
19> ]
19>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(364): error C2039: 'iterator_category' : is not a member of '`global namespace''
19>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(364): error C2146: syntax error : missing ';' before identifier 'iterator_category'
19>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(364): error C2602: 'std::iterator_traits<_Iter>::iterator_category' is not a member of a base class of 'std::iterator_traits<_Iter>'
19> with
19> [
19> _Iter=int
19> ]
19> c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(364) : see declaration of 'std::iterator_traits<_Iter>::iterator_category'
19> with
19> [
19> _Iter=int
19> ]
19>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(364): error C2868: 'std::iterator_traits<_Iter>::iterator_category' : illegal syntax for using-declaration; expected qualified-name
19> with
19> [
19> _Iter=int
19> ]
19>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(365): error C2825: '_Iter': must be a class or namespace when followed by '::'
19>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(365): error C2039: 'value_type' : is not a member of '`global namespace''
19>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(365): error C2146: syntax error : missing ';' before identifier 'value_type'
19>c:\program files (x86)\microsoft visual studio 11.0\vc\include\xutility(365): error C2602: 'std::iterator_traits<_Iter>::value_type' is not a member of a base class of 'std::iterator_traits<_Iter>'

谁能告诉我我对 std::basic_string 的预先声明有什么问题?

最佳答案

您在声明中省略了几个模板参数。正确的看起来像:

template<class charT, class traits = char_traits<charT>,
class Allocator = allocator<charT> >
class basic_string;

不过不要尝试自己做。使用 <string> .

关于c++ - 为什么预先声明 std::basic_string<T> 会破坏 boost::regex?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18983258/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com