在boost :: multi_array构建器上编译错误

时间:2012-09-29 11:27:51

标签: c++ boost boost-multi-array

据说如果我们想要更有效地使用multi_array,我们最好使用multi_array构建器。但是,我对模板和提升都是新手,我试图从一本书中复制一些代码。它看起来像这样:

class multi_builder : boost::noncopyable    
{
public:
    typedef boost::multi_array<T,N> array_type;
    typedef boost::shared_ptr<array_type > type;    
private:
    boost::any ext; 
public:
    multi_builder() : ext(boost::extents){}
    ~multi_builder(){}
    template<std::size_t n>
    void dim(std::size_t x)
    {
        BOOST_STATIC_ASSERT(n >= 0 && n < N);   
        ext = boost::any_cast<boost::detail::multi_array::extent_gen<n> >(ext) [x];
    }
    boost::type create(void)
    {
        return boost::type<array_type>(new array_type(boost::any_cast<boost::detail::multi_array::extent_gen<N> >(ext)));
    }
};

然而,当我尝试在这样的代码中使用它时:

multi_builder<int,2> builder;
builder.dim<0>(2);  
builder.dim<1>(2);  
BOOST_AUTO(mp,builder.create());   
for(int i = 0,v = 0; i < 2; ++i)
    for(int j = 0; j < 2; ++j)
        (*mp)[i][j] = v++;  

编译器会生成以下错误:

error:invalid use of template-name 'boost::type' without an argument list
error:'class multi_builder<int, 2u>' has no member named 'create'.
error:invalid type in declaration before '=' token
error:'class multi_builder<int, 2u>' has no member named 'create'
error:invalid type argument of 'unary *'

有人能告诉我如何修复错误吗?

1 个答案:

答案 0 :(得分:0)

从它的外观来看,create()的返回类型缺少模板参数列表。我没有使用过这个Boost组件,但根据返回值的方式,它可能看起来像这样:

boost::type<array_type> create(void)
相关问题