【发布时间】:2020-05-17 23:23:57
【问题描述】:
我正在尝试创建一个类似于搜索历史记录的对象,但我遇到了指向搜索目标的迭代器的问题,这导致我的程序在初始化时崩溃。另一个问题是,当我尝试更改一些指针(f.ex -> 到 * )时,它找不到任何函数
.ccp
History::History(std::vector<std::unique_ptr<Brick>>::iterator _itr)
: itr(_itr)
{
this->itr_text = (*itr)->getText(); // <--- this line is strange
// some SFML
}
History::~History()
{
}
.hpp
class History
{
public:
History(std::vector<std::unique_ptr<Brick>>::iterator _itr);
~History();
private:
std::vector<std::unique_ptr<Brick>>::iterator itr;
std::string itr_text;
/// some SFML
};
我正计划添加更多迭代器函数,所以我会感谢你的帮助
【问题讨论】:
-
你如何使用这个
History类?迭代器“指向”什么?向量元素是有效的非空指针吗?请edit您的问题包括minimal reproducible example。