【发布时间】:2016-02-14 14:26:36
【问题描述】:
我有以下形式的结构
class THistory
{
/* */
public:
UInt32 userId;
UInt32 trip;
};
列表如下
THistory hist2;
std::list<THistory> temp;
std::list<THistory>::iterator it = temp.begin();
hist2.userId=userId;//passed by some function storing in tempory structure
hist2.trip=trip;//passed by some function storing in tempory structure
temp.push_back(hist2);//Pusing into list
我的问题是我可以访问
it->userId and
it->trip
但是我如何访问整个结构。我需要将整个结构指针传递给其他函数而不是单个元素。另外,在推入列表之前使用临时结构填充结构元素的上述方法是否正确。
根据答案更新: 我按如下方式传递迭代器
getLocations(&*it);
定义:
getLocations( THistory *hist){
////
}
我的代码可以编译,但在运行时崩溃
“错误:Iterator is deferencable”我进入函数内部,它在库内部调用列表函数并在此处崩溃
reference operator*() const
{ // return designated value
return ((reference)**(_Mybase *)this);
}
我越来越糊涂了。希望这不是愚蠢的错误
【问题讨论】:
-
"但是我如何访问整个结构。"
(*it) -
请创建一个Minimal, Complete, and Verifiable Example 并展示给我们。
-
std::list<THistory>::iterator it = temp.begin();- 嗯...查看您的代码,nothing 那时在列表中,对吗?该迭代器不会神奇地开始指向您在获取它之后插入的内容。 -
是的,我错过了... thnx..