我正在创建迭代器:
typename Report::container_type_for_processed_files::const_iterator beg = rep.processed_files().begin();
typename Report::container_type_for_processed_files::const_iterator end = rep.processed_files().end();
我的报告类看起来如下:
class Report
{
public:
typedef std::map<boost::filesystem3::path,
std::pair<unsigned long long/*code*/,
unsigned long long/*comment*/> > container_type_for_processed_files;
container_type_for_processed_files processed_files()const;
private:
container_type_for_processed_files processed_files_;
};
cpp中的已处理文件如下所示:
typename Report::container_type_for_processed_files Report::processed_files()const
{
return processed_files_;
}
但在初始化迭代器后,如第一行所示:
typename Report::container_type_for_processed_files::const_iterator beg = rep.processed_files().begin();
typename Report::container_type_for_processed_files::const_iterator end = rep.processed_files().end();
while (beg != end)
{
qDebug() << beg->first.c_str();//here I'm getting runtime error
fout << "File name: " << (beg->first).c_str();
++beg;
}
我收到错误消息:无效的参数传递给C运行时函数。
尝试初始化迭代器时,我还在输出窗格上收到消息:
(内部错误:在psymtab中读取了pc 0x201,但在symtab中没有读取。)
这是怎么回事?
最佳答案
如果没有可编译的样本,我不确定这是您的问题,但这看起来很麻烦:
container_type_for_processed_files processed_files() const;
您应该最有可能将
const&
返回到该容器中,否则该函数将返回(可能是临时的)基础容器的副本,并且您的迭代器最终将变为无效(不是对同一对象的迭代器,并且可能对生命已结束的临时人员)。尝试:
container_type_for_processed_files const& processed_files() const;
关于c++ - 奇怪的行为或std::map::const_iterator,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8694397/