Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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++_Templates_Iterator_Template Classes - Fatal编程技术网

C++ 使用迭代器模板类作为函数的参数

C++ 使用迭代器模板类作为函数的参数,c++,templates,iterator,template-classes,C++,Templates,Iterator,Template Classes,我不明白为什么这一行被称为复制构造函数,尽管我的构造函数中有一个参数。arguments构造函数参数专门为此设计编写。 关于一个类似的问题,我所发现的只是typename的使用。但这并没有解决我的问题 return Graph_iterator_Vertex(Vertexs.begin()); 结构图\u迭代器\u顶点 { 私人: typename std::vector::迭代器迭代器; 公众: 图\迭代器\顶点(typename std::\向量\常量\迭代器\迭代器) { 迭代器=迭代

我不明白为什么这一行被称为复制构造函数,尽管我的构造函数中有一个参数。arguments构造函数参数专门为此设计编写。 关于一个类似的问题,我所发现的只是typename的使用。但这并没有解决我的问题

return Graph_iterator_Vertex(Vertexs.begin()); 
结构图\u迭代器\u顶点
{
私人:
typename std::vector::迭代器迭代器;
公众:
图\迭代器\顶点(typename std::\向量\常量\迭代器\迭代器)
{
迭代器=迭代器_
}
};
常量图\迭代器\顶点开始(void)常量
{
返回图\迭代器\顶点(Vertexs.begin());
}
在哪里

struct Graph_iterator_Vertex
    {
    private:
        typename std::vector<Vertex<Type_Of_Value_Vertex, Type_Of_Value_Edge>>::iterator iterator;

    public:

        Graph_iterator_Vertex(typename std::_Vector_const_iterator<std::vector<Vertex<Type_Of_Value_Vertex, Type_Of_Value_Edge>>> iterator_)

        {
            iterator=iterator_
        }
    };

    const Graph_iterator_Vertex begin(void) const 
    {
        return Graph_iterator_Vertex(Vertexs.begin()); 
    }
std::向量顶点;
错误:

std::vector<Vertex<Type_Of_Value_Vertex, Type_Of_Value_Edge>> Vertexs;
错误C2440::无法转换“Graph::Graph\u iterator\u Vertex”中的std::\u Vector\u const\u iterator”
您应该使用

error C2440: <function-style-cast>: can not be converted std::_Vector_const_iterator<_Myvec>"in "Graph<Type_Of_Value_Vertex,Type_Of_Value_Edge>::Graph_iterator_Vertex" 
std::vector::const_迭代器
而不是

std::vector<Vertex<Type_Of_Value_Vertex, Type_Of_Value_Edge>>::const_iterator
std::_Vector_const_迭代器
作为函数参数的类型。

您应该使用

error C2440: <function-style-cast>: can not be converted std::_Vector_const_iterator<_Myvec>"in "Graph<Type_Of_Value_Vertex,Type_Of_Value_Edge>::Graph_iterator_Vertex" 
std::vector::const_迭代器
而不是

std::vector<Vertex<Type_Of_Value_Vertex, Type_Of_Value_Edge>>::const_iterator
std::_Vector_const_迭代器

作为函数参数的类型。

了解
iterator
const\u iterator
之间的区别。还了解
const
成员函数(例如代码中的
begin
)对成员数据的作用(例如
Vertexs
;注意,它会改变其常量!)。了解
迭代器
常量迭代器
之间的区别。还了解
常量
成员函数(例如代码中的
开始
)对成员数据的作用(例如
顶点
;注意它会改变常量!)哦,对不起。我没有注意到const。谢谢你。@ GGHA,如果你觉得我的答案有帮助,请考虑接受它。谢谢。@ GGHA,<代码> STD::ER有帮助,请考虑接受它。谢谢。@ GGHA的<代码> STD::