为什么预先声明 std::basic_string<T> 会破坏 boost::regex?
Why does predeclaring std::basic_string<T> break boost::regex?
使用Microsoft Visual Studio 2012编译器,以及boost 1.53,我有一些工作代码用于:
#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)boostboost_1_53boostregexv4instances.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)boostboost_1_53boostregexv4instances.hpp(106): error C2065: 'const_iterator' : undeclared identifier
19>c:program files (x86)boostboost_1_53boostregexv4instances.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.0vcincludexutility(364): error C2825: '_Iter': must be a class or namespace when followed by '::'
19> c:program files (x86)boostboost_1_53boostregexv4iterator_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)boostboost_1_53boostregexv4match_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)boostboost_1_53boostregexv4instances.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.0vcincludexutility(364): error C2039: 'iterator_category' : is not a member of '`global namespace''
19>c:program files (x86)microsoft visual studio 11.0vcincludexutility(364): error C2146: syntax error : missing ';' before identifier 'iterator_category'
19>c:program files (x86)microsoft visual studio 11.0vcincludexutility(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.0vcincludexutility(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.0vcincludexutility(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.0vcincludexutility(365): error C2825: '_Iter': must be a class or namespace when followed by '::'
19>c:program files (x86)microsoft visual studio 11.0vcincludexutility(365): error C2039: 'value_type' : is not a member of '`global namespace''
19>c:program files (x86)microsoft visual studio 11.0vcincludexutility(365): error C2146: syntax error : missing ';' before identifier 'value_type'
19>c:program files (x86)microsoft visual studio 11.0vcincludexutility(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>
.
谁能告诉我我的预先声明有什么问题
std::basic_string
?
它有三个模板参数:
template<class charT, class traits = char_traits<charT>,
class Allocator = allocator<charT> >
class basic_string;
但是没有理由自己声明标准类型,正如你已经证明的那样,有一个很好的理由不这样做。所以不要那样做;如果需要声明,请包含标头。
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- boost::进程间消息队列引发错误
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- cmake如何在fedora工作站中找到boost静态库包
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- Boost Graph Library,修复节点大小
- 什么是"#include <boost/functional/hash.hpp> "?
- 基于boost的程序的静态链接——zlib问题
- C++:如何在CLion IDE中安装Boost
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 如何在boost beast http请求中设置http头
- Boost Spirit,获取迭代器内部语义动作
- boost::asio::steady_timer()与sleep()我应该使用哪一个
- boost::asio如何生成多个协同程序,然后加入它们
- 当我尝试使用 sstream 和分面将 Boost Time_duration转换为字符串时,我没有得到所需的格式
- EASTL矢量<向量<int>>连续的
- Visual Studio(或任何其他工具)能否将地址解释为调用堆栈(boost上下文)的开头
- 如何使用boost::具有嵌套结构和最小代码更改的序列化
- 使用Boost Interprocess创建托管共享内存需要很长时间
- 使用 std::vector<boost::shared_ptr<Base_Class>> 或 boost::p tr_vector 的性能注意事项是什么<Base>