在我的 Objective-C 应用程序中运行 C++ 代码时,我遇到了一个相当奇怪的异常。我正在使用 libxml2 读取 XSD 文件。然后,我将相关标签作为 Tag 类的实例存储在 std::list 中。然后我使用列表上的迭代器将此列表复制到 std::vector 中。但是,有时列表中的某些元素不会复制到向量中。任何帮助将不胜感激。
printf("\n length list = %lu, length vector = %lu\n",XSDFile::tagsList.size(), XSDFile::tags.size() );
std::list<Tag>::iterator it = XSDFile::tagsList.begin();
//result: length list = 94, length vector = 0
/*
for(;it!=XSDFile::tagsList.end();++it)
{
XSDFile::tags.push_back(*it); //BAD_ACCESS code 1 . . very bizarre . . . . 25
}
*/
std::copy (XSDFile::tagsList.begin(), XSDFile::tagsList.end(), std::back_inserter (XSDFile::tags));
printf("\n Num tags in vector = %lu\n", XSDFile::tags.size());
if (XSDFile::tagsList.size() != XSDFile::tags.size())
{
printf("\n length list = %lu, length vector = %lu\n",XSDFile::tagsList.size(), XSDFile::tags.size() );
//result: length list = 94, length vector = 83
}