我无法编译以下代码:
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/include/qi.hpp>
#include <string>
struct function
{
std::string ret_type;
std::string name;
};
BOOST_FUSION_ADAPT_STRUCT(
function,
(std::string, ret_type)
(std::string, name)
)
int main() {}
Run Code Online (Sandbox Code Playgroud)
带有boost 1.54的MSVC-11.0给出了以下错误:
1>main.cpp(6084): error C3203: 'function' : unspecialized class template can't be used as a template argument for template parameter 'Sequence', expected a real type
1>main.cpp(6084): error C2955: 'boost::function' : use of class template requires template argument list
1> e:\libs\boost_1_54_0\boost\function\function_fwd.hpp(33) : see declaration of 'boost::function'
1>main.cpp(6084): error C2913: explicit specialization; 'boost::fusion::traits::tag_of' is not a specialization of a class template
1>main.cpp(6084): error C3203: 'function' : unspecialized class template can't be used as a template argument for template parameter 'Seq', expected a real type
1> e:\libs\boost_1_54_0\boost\function\function_fwd.hpp(33) : see declaration of 'boost::function'
1>main.cpp(6084): error C2913: explicit specialization; 'boost::fusion::extension::access::struct_member' is not a specialization of a class template
1> e:\libs\boost_1_54_0\boost\function\function_fwd.hpp(33) : see declaration of 'boost::function'
1>main.cpp(6084): error C2913: explicit specialization; 'boost::fusion::extension::struct_member_name' is not a specialization of a class template
1> e:\libs\boost_1_54_0\boost\function\function_fwd.hpp(33) : see declaration of 'boost::function'
1>main.cpp(6084): error C2913: explicit specialization; 'boost::fusion::extension::struct_size' is not a specialization of a class template
1> e:\libs\boost_1_54_0\boost\function\function_fwd.hpp(33) : see declaration of 'boost::function'
1>main.cpp(6084): error C2913: explicit specialization; 'boost::fusion::extension::struct_is_view' is not a specialization of a class template
1> e:\libs\boost_1_54_0\boost\function\function_fwd.hpp(33) : see declaration of 'boost::function'
1>main.cpp(6084): error C2913: explicit specialization; 'boost::mpl::sequence_tag' is not a specialization of a class template
Run Code Online (Sandbox Code Playgroud)
如果我删除"boost/spirit/include/qi.hpp"包含或明确告诉函数结构放在全局命名空间内,一切都很好:
BOOST_FUSION_ADAPT_STRUCT(
::function,
(std::string, ret_type)
(std::string, name)
)
Run Code Online (Sandbox Code Playgroud)
使用BOOST_FUSION_ADAPT_STRUCT宏时,它会创建一些类型并将它们放在boost命名空间中.这些类型的定义将引用您提供的结构名称.
在您的情况下,您为结构提供了一个名称,该名称与boost命名空间中已存在的名称相同:boost::function显然,boost qi标头间接包含该名称.由于生成的代码位于boost命名空间中,因此它认为您要引用boost::function而不是您的类型::function.
出于这个原因,文档说:"struct_name应该是要调整的结构的完全命名空间限定名称".因此::,在类型名称之前添加全局命名空间限定符的解决方案是正确的.
| 归档时间: |
|
| 查看次数: |
591 次 |
| 最近记录: |