没有重载函数需要 2 个参数错误,并带有 boost::assign::list_of

No overloaded function takes 2 arguments error with boost::assign::list_of

本文关键字:boost list of assign 错误 函数 重载 参数      更新时间:2023-10-16

为什么会出现错误:Test::Test: no overloaded function takes 2 arguments

class Test
{
public:
    Test(const std::vector<int>&)
    {
    }
};
Test test(boost::assign::list_of(4));

boost::assign::list_of 的实现要求容器类型(在本例中为 Test 类)具有双参数构造函数,该构造函数采用第一个和最后一个迭代器(也称为 range)来初始化容器。

具体来说,错误来自下面的行,返回容器在 boost::assign_detail::转换器类的转换方法中:

    template< class Container >
    Container convert( const Container*, default_type_tag ) const
    {
        return Container( begin(), end() );
    }

hmjd 的解决方法成功的原因是 std::vector 有一个构造函数需要两个迭代器。