gpt4 book ai didi

c++ - boost::mpl::tag::type 编译错误

转载 作者:行者123 更新时间:2023-11-28 00:44:51 25 4
gpt4 key购买 nike

我最近尝试了 boost::mpl,它看起来既棒又可怕。有时编译错误信息比较困惑。

这次我在以下代码上遇到了问题:

#include <iostream>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/integral_c_tag.hpp>
#include <boost/mpl/tag.hpp>
#include <typeinfo>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/range_c.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/copy.hpp>

//使用元函数标签<>获取类型,使mpl只输出整数。

struct mpl_func2
{
template<typename T>
void operator()(T t)
{
if(boost::is_same<boost::mpl::tag<T>::type, boost::mpl::integral_c_tag>::value)
{cout<<t<<',';}
}
};

错误信息如下:

错误:'template struct boost::is_same' 的模板参数列表中参数 1 的类型/值不匹配

错误:需要一个类型,得到“boost::mpl::tag::type”

最佳答案

你应该使用

typename boost::mpl::tag<T>::type

因为 typedependent-name。阅读有关它的更多信息 here

关于c++ - boost::mpl::tag<T>::type 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16768350/

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