Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/160.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_Iterator_Variable Assignment_Ambiguity - Fatal编程技术网

C++ 列表迭代器不';不能被分配

C++ 列表迭代器不';不能被分配,c++,stl,iterator,variable-assignment,ambiguity,C++,Stl,Iterator,Variable Assignment,Ambiguity,很抱歉,问题标题含糊不清,但我这里有以下类型定义: typedef std::list<AnimationKeyframe> Timeline; typedef Timeline::iterator Keyframe; 我还有一个复制/赋值构造函数,因为我在存储迭代器(这似乎是个坏主意), 问题就在那里 Keyframe myTemp, hisTemp; this->left = this->timeline.begin(); // assigns myTemp = t

很抱歉,问题标题含糊不清,但我这里有以下类型定义:

typedef std::list<AnimationKeyframe> Timeline;
typedef Timeline::iterator Keyframe;
我还有一个复制/赋值构造函数,因为我在存储迭代器(这似乎是个坏主意), 问题就在那里

Keyframe myTemp, hisTemp;
this->left = this->timeline.begin(); // assigns
myTemp = this->timeline.begin(); // assigns
hisTemp = that.timeline.begin() // does not assign
当我试图用其中一个“that”(另一个foo)指定一个关键帧时,我会得到看起来像是模糊问题的错误

二进制“=”:未找到 接受类型为的右侧操作数 'std::_List_const_iterator' (或没有可接受的转换)

其他信息:

  with
 [
     _Mylist=std::_List_val<AnimationKeyframe,std::allocator<AnimationKeyframe>>
 ]
  could be 'std::_List_iterator<_Mylist> &std::_List_iterator<_Mylist>::operator =(const std::_List_iterator<_Mylist> &)'
 with
 [
     _Mylist=std::_List_val<AnimationKeyframe,std::allocator<AnimationKeyframe>>
 ]
 while trying to match the argument list '(Keyframe, std::_List_const_iterator<_Mylist>)'
 with
 [
     _Mylist=std::_List_val<AnimationKeyframe,std::allocator<AnimationKeyframe>>
 ]
与
[
_Mylist=std::\u列表\u值
]
可以是“std::_List_iterator&std:_List_iterator::operator=(常量std::_List_iterator&)”
具有
[
_Mylist=std::\u列表\u值
]
尝试匹配参数列表时“(关键帧,标准::_list_const_iterator)”
具有
[
_Mylist=std::\u列表\u值
]
是什么导致了这种奇怪的行为?
我怀疑我使用迭代器作为状态的糟糕风格……但除了保留指针之外,我不知道还能做什么。

看起来
常量(可能是常量引用)
begin()常量
返回一个
常量迭代器
,而不是
迭代器

没有从常量迭代器转换为迭代器的原因如下:

void foo(const std::vector<int> &vec) {
    std::vector<int>::iterator it = vec.begin(); // if this compiled...
    *it = 5;  // then this would attempt to modify a vector taken by const ref
}
void foo(const std::vector&vec){
std::vector::iterator it=vec.begin();//如果编译了此函数。。。
*it=5;//那么这将尝试修改const ref获取的向量
}

看起来好像
常量(可能是常量引用)
begin()常量
返回一个
常量迭代器
,而不是
迭代器

没有从常量迭代器转换为迭代器的原因如下:

void foo(const std::vector<int> &vec) {
    std::vector<int>::iterator it = vec.begin(); // if this compiled...
    *it = 5;  // then this would attempt to modify a vector taken by const ref
}
void foo(const std::vector&vec){
std::vector::iterator it=vec.begin();//如果编译了此函数。。。
*it=5;//那么这将尝试修改const ref获取的向量
}