Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/147.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将迭代器转换为构造函数_C++_Stl_Constructor_Iterator - Fatal编程技术网

C++ 将迭代器转换为构造函数

C++ 将迭代器转换为构造函数,c++,stl,constructor,iterator,C++,Stl,Constructor,Iterator,我想知道如何为接受任何STL输入迭代器的自定义类(本例中为链表)编写构造函数。我已经创建了一个自定义迭代器类,它绑定到我的列表类 这个很好用 template <typename T> List<T>::List(Iterator beg, Iterator end) : first_(0) { while (beg != end) insertLast(*beg++); } 模板 List::List(迭代器beg,迭代器end):

我想知道如何为接受任何STL输入迭代器的自定义类(本例中为链表)编写构造函数。我已经创建了一个自定义迭代器类,它绑定到我的列表类

这个很好用

template <typename T>  
List<T>::List(Iterator beg, Iterator end) : first_(0) {  
    while (beg != end)  
        insertLast(*beg++);
}
模板
List::List(迭代器beg,迭代器end):first_0{
while(beg!=结束)
insertLast(*beg++);
}
我已经成功地创建了一个构造函数来接收这样的列表迭代器

List<T>::List(typename list<T>::iterator s, typename list<T>::iterator e) :
    first_(0) {  
    while (s != e)   
        insertLast(*s++);
List::List(typename List::iterator s,typename List::iterator e):
第一(0){
而(s!=e)
insertLast(*s++);
我的STL fu在如何将其推广到接受任何输入迭代器方面还没有达到标准
有人帮忙吗


谢谢!

我想事情就这么简单:

template <typename T, typename Iterator>  
List <T>::List(Iterator beg, Iterator end) : first_(0) {  
    while (beg != end)  
        insertLast(*beg++);
}
模板
List::List(迭代器beg,迭代器end):first_0{
while(beg!=结束)
insertLast(*beg++);
}

我认为这很简单:

template <typename T, typename Iterator>  
List <T>::List(Iterator beg, Iterator end) : first_(0) {  
    while (beg != end)  
        insertLast(*beg++);
}
模板
List::List(迭代器beg,迭代器end):first_0{
while(beg!=结束)
insertLast(*beg++);
}

这可能只是一个模板化构造函数

template <class T>
class List
{
    public:
    template <class Iter>
    List(Iter from, Iter to);
    ...
};

template <class T>
template <class Iter>
List<T>::List(Iter from, Iter to) {...}
模板
班级名单
{
公众:
模板
清单(国际热核实验反应炉起,国际热核实验反应炉至);
...
};
模板
模板
列表::列表(国际热核实验堆从,国际热核实验堆到){…}

这可能只是一个模板化构造函数

template <class T>
class List
{
    public:
    template <class Iter>
    List(Iter from, Iter to);
    ...
};

template <class T>
template <class Iter>
List<T>::List(Iter from, Iter to) {...}
模板
班级名单
{
公众:
模板
清单(国际热核实验反应炉起,国际热核实验反应炉至);
...
};
模板
模板
列表::列表(国际热核实验堆从,国际热核实验堆到){…}